Solved

Capture sub second response times in VB

Posted on 2002-05-30
7
247 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 50

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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

775 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