Solved

Capture sub second response times in VB

Posted on 2002-05-30
7
239 Views
Last Modified: 2010-05-02
I am writing a utility to use for performance testing.  Does anyone know of a VB function I can invoke to capture sub second response times or a way that I can create my own.  The standard now() function only returns the value of the system clock which does not break down the time futher than a second.  Likewise the date functions do not support sub second time intervals either.
0
Comment
Question by:mkeysaer
7 Comments
 
LVL 75

Accepted Solution

by:
Anthony Perkins earned 100 total points
ID: 7045720
Take a look at the API function:
Declare Function GetTickCount Lib "kernel32" () As Long

Anthony
0
 
LVL 1

Expert Comment

by:Toad224
ID: 7046047
Use    Timer    ...  it gives it in times accurate lessa than a second by returning a single...  ie. 82390.95

Good Luck.
0
 
LVL 49

Expert Comment

by:Ryan Chong
ID: 7046484
I'm with Anthony, you can write you codes to test the time bypassed like this:

Private Declare Function GetTickCount Lib "kernel32" () As Long

Private Sub Command1_Click()
    Dim strTime As Long, stpTime As Long
    strTime = GetTickCount
   
    'Do the process here
    For i = 1 To 1000
        DoEvents
        Debug.Print i
    Next i
   
    'strTime returns time in miliseconds (1000 = 1 second)
    strTime = GetTickCount - strTime
   
    'Convert it to 2 decimal format
    MsgBox Format$(strTime / 1000, "#.00")
End Sub
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 4

Expert Comment

by:mcoop
ID: 7046542
I thought ticks are approx 18mS resolution... ?  (i.e. backward compatible with the old DOS clock...)

Does anyone know the correct answer ??

Sorry ryancs - I just want to make sure for my own knowledge as well !
0
 
LVL 1

Expert Comment

by:Toad224
ID: 7046703
Yea... but  Timer  is basically the VB way of doing it...  like you would use MsgBox rather than the MessageBox Win API or like you would do text1.text = ""  rather than SendDlgItemMessage or SendMessage w/ WM_SETTEXT   Both ways work great, though

Good luck!
0
 
LVL 2

Expert Comment

by:Crin
ID: 7047015
Hi,
When I developed profiler application for myself I used this:

Private Type SYSTEMTIME
  wYear As Integer
  wMonth As Integer
  wDayOfWeek As Integer" & ProfSpecLine
  wDay As Integer" & ProfSpecLine
  wHour As Integer" & ProfSpecLine
  wMinute As Integer" & ProfSpecLine
  wSecond As Integer" & ProfSpecLine
  wMilliseconds As Integer" & ProfSpecLine
End Type

Private Declare Sub GetSystemTime Lib ""kernel32"" (ByRef lpSystemTime As SYSTEMTIME)

After that you can do

Dim A as SYSTEMTIME
GetSystemTime A

and access A.wYear ... A.wMilliseconds.

Sincerely,
Crin

0
 

Author Comment

by:mkeysaer
ID: 7047569
A lot of good answers.  Thanks for the input everyone!
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now