如题

解决方案 »

  1.   

    在代码开始运行之前读出timer,运行之后读出timer,相减就行了
      

  2.   

    dim starttime,endtime as double
    starttime=timer
    开始你的代码
    endtime=timer
    msgbox endtime-starttime(这就是代码执行的时间,秒位单位)
      

  3.   

    可以放一个Timer控件,把Interval设为1,引入一个模块变量(Long型),在代码开始时把它设为0,Timer控件的Timer事件里,对该变量进行加1操作,在代码执行完后,读出这个变量。OK?
      

  4.   

    楼上的估计没有实践过, 在win9x里面, timer的有效范围在50以上(即小于20Hz), 设置timer小于50一下的运行结果依赖于硬件,但即使在配置较好的机器上也达不到20以下(50hz)
    在nt环境, timer的表现略好, interval可设在5以上, 对更小的interval则无能为力
    以上结论系编译后在6台不同配置不同os情况下得到的
      

  5.   

    楼上的没错,其实Timer控件的准确性不高,就算设为50,实际间隔很可能也不是这个数。不过比用Time或者Now函数要精确多了。
    刚才想到了另一个函数GetTickCount,这个函数很管用,建议楼主用它,因为是API函数,所以得先声明了。GetTickCount
    The GetTickCount function retrieves the number of milliseconds that have elapsed since the system was started. It is limited to the resolution of the system timer. If you need a higher resolution timer, use amultimedia timer or a high-resolution timer. DWORD GetTickCount(VOID)
     
    Parameters
    This function has no parameters. Return Values
    The return value is the number of milliseconds that have elapsed since the system was started. Res
    The following table describes the resolution of the system timer. System Resolution 
    Windows NT 3.5 and later The system timer runs at approximately 10ms. 
    Windows NT 3.1 The system timer runs at approximately 16ms. 
    Windows 95 and later The system timer runs at approximately 55ms. 
    The elapsed time is stored as a DWORD value. Therefore, the time will wrap around to zero if the system is run continuously for 49.7 days. Windows NT: To obtain the time elapsed since the computer was started, look up the System Up Time counter in the performance data in the registry key HKEY_PERFORMANCE_DATA. The value returned is an 8-byte value. QuickInfo
      Windows NT: Requires version 3.1 or later.
      Windows: Requires Windows 95 or later.
      Windows CE: Requires version 1.0 or later.
      Header: Declared in winbase.h.
      Import Library: Use kernel32.lib.
      

  6.   

    timeGetTime / QueryPerformanceFrequency & QueryPerformanceCount / rdtsc /...