Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Timer in VB Script

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,38523
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Timer in VB Script
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 Timer in VB Script - 10/10/2006 1:47:30 AM   
  anthony12345

 

Posts: 5
Score: 0
Joined: 10/10/2006
Status: offline
Hi All,

I'm trying to calucalte the time between 2 buttons being clicked.

I'm using a PDA with windows Mobile. I'm coding on a PC with VBScript

Obvious function to call is Timer() and do the difference between Timer1 and Timer2, but the result comes to the nearest second.

In Excel with VB it's fine, and I've tried to take the result and multiply by 1000 to obtain the milliseconds but the result is 0

Any ideas / suggestions?

Thanks

 
 
Post #: 1
 
 RE: Timer in VB Script - 10/10/2006 1:57:50 AM   
  DiGiTAL.SkReAM


Posts: 1183
Score: 7
Joined: 9/6/2005
From: Florida, USA
Status: online

      



_____________________________

"Would you like to touch my monkey?" - Dieter (Mike Meyers)

"It is better to die like a tiger, than to live like a pussy."
-Master Wong, from Balls of Fury

(in reply to anthony12345)
 
 
Post #: 2
 
 RE: Timer in VB Script - 10/10/2006 2:10:53 AM   
  ehvbs

 

Posts: 2169
Score: 50
Joined: 6/22/2005
From: Germany
Status: offline
Hi anthony12345,

the VBScript Timer function has a resolution of 1 sec:

    "Returns the number of seconds that have elapsed since 12:00 AM (midnight)."

the VBA Timer function is more useful:

    "Unter Microsoft Windows gibt die Timer-Funktion Bruchteile einer Sekunde zurück."

(sorry about the German). To get a better resolution in a VBScript application, you'll
have to use some other means (Javascript, a suitable COM object). What kind of script
provides the buttons you mentioned?

(in reply to DiGiTAL.SkReAM)
 
 
Post #: 3
 
 RE: Timer in VB Script - 10/10/2006 2:22:36 AM   
  DiGiTAL.SkReAM


Posts: 1183
Score: 7
Joined: 9/6/2005
From: Florida, USA
Status: online
ehvbs,
I apparently am not understanding what you mean by "resolution of 1 second".
When I am timing my functions for performance tuning, i use the vbscript timer function, and it gives me times like 2.12543 seconds.

_____________________________

"Would you like to touch my monkey?" - Dieter (Mike Meyers)

"It is better to die like a tiger, than to live like a pussy."
-Master Wong, from Balls of Fury

(in reply to ehvbs)
 
 
Post #: 4
 
 RE: Timer in VB Script - 10/10/2006 2:26:31 AM   
  anthony12345

 

Posts: 5
Score: 0
Joined: 10/10/2006
Status: offline
Thanks for the info.

The software i'm using only accepts VBscript or Jscript

In this case do you know what the function name is to say:

' [click 1]
dim start, finish
start = Timer

' [click 2]
finish = Timer - start
msgbox("interval is " & finish)

??

May be a stupid question, but i'm just starting to learn JScript too...

Thanks!! / Vielen Dank!!!



(in reply to ehvbs)
 
 
Post #: 5
 
 RE: Timer in VB Script - 10/10/2006 2:34:32 AM   
  anthony12345

 

Posts: 5
Score: 0
Joined: 10/10/2006
Status: offline
Hi DiGiTAL.SkReAM

I can't seem to use the wscript function in my vbscript... And it's not listed as a vbscript function.. how do i get it to work for me?

Thanks!!!


(in reply to anthony12345)
 
 
Post #: 6
 
 RE: Timer in VB Script - 10/10/2006 3:28:42 AM   
  ehvbs

 

Posts: 2169
Score: 50
Joined: 6/22/2005
From: Germany
Status: offline
Hi DiGiTAL.SkReAM,

you are right: the resolution of the VBScript Timer function is better than 1 sec - I assume
1 millisec, because this scale is explicitly stated for the WScript.Sleep method. I was mislead
by the VBScript Docs. This code and its output


      

should prove it.

Hi anthony12345,

as your code obviously isn't hosted by w|cscript.exe, you can't use the WScript object provided
by these hosts to output/echo to the console/a messagebox. Use a suitable output function
of your host application (I still would like to know about the environment of your script), e.g.
MsgBox or document.write or setting the value of an edit field.

This hta application


      

should show you, how to do it in an HTML GUI.

Back to your first problem "but the result comes to the nearest second": As this can't be blamed
to the Timer() function, show us (the relevant part of) your code. Perhaps some (implicit) conversions
cause your problem.



(in reply to anthony12345)
 
 
Post #: 7
 
 RE: Timer in VB Script - 10/10/2006 3:42:13 AM   
  DiGiTAL.SkReAM


Posts: 1183
Score: 7
Joined: 9/6/2005
From: Florida, USA
Status: online
quote:

ORIGINAL: ehvbs

Hi DiGiTAL.SkReAM,

you are right: the resolution of the VBScript Timer function is better than 1 sec - I assume
1 millisec, because this scale is explicitly stated for the WScript.Sleep method. I was mislead
by the VBScript Docs. This code and its output
<-El Snippo->


ya see, that's yer problem... you actually READ the docs.

_____________________________

"Would you like to touch my monkey?" - Dieter (Mike Meyers)

"It is better to die like a tiger, than to live like a pussy."
-Master Wong, from Balls of Fury

(in reply to ehvbs)
 
 
Post #: 8
 
 RE: Timer in VB Script - 10/11/2006 1:26:48 AM   
  anthony12345

 

Posts: 5
Score: 0
Joined: 10/10/2006
Status: offline
Thanks for the messages,

The problem is that I'm using VBScript code on a PDA, i.e. I'm coding on my PC and uploading the code to a PDA, then checking the result

Here's the code:

dim time1

Sub btnbtn1_OnClick()
  time1 = Timer()
End Sub

Sub btnbtn2_OnClick()
   dim time2
   tbxtbx1.value = (Timer()-time1)
End Sub

The problem may come from the PDA that does not keep track of time less than a second?

Thanks

(in reply to DiGiTAL.SkReAM)
 
 
Post #: 9
 
 RE: Timer in VB Script - 10/11/2006 1:57:19 AM   
  ehvbs

 

Posts: 2169
Score: 50
Joined: 6/22/2005
From: Germany
Status: offline
Hi anthony12345,

you could try something like

  Sub btnbtn1_OnClick()
    time1 = Timer()
    MsgBox TypeName( time1 )
  End Sub

to check the datatype of the return value of the Timer() function and

  Sub btnbtn2_OnClick()
     dim time2
     time2 =  (Timer()-time1)
     tbxtbx1.value = time2
     MsgBox (time2 = Abs( time2 ))
End Sub

to check whether there are fractional parts. Otherwise you'll have to
read the Docs (DiGiTAL.SkReAM's opinions not withstanding).

Good luck!

(in reply to anthony12345)
 
 
Post #: 10
 
 RE: Timer in VB Script - 10/12/2006 1:01:53 AM   
  DiGiTAL.SkReAM


Posts: 1183
Score: 7
Joined: 9/6/2005
From: Florida, USA
Status: online
quote:

ORIGINAL: ehvbs
to check whether there are fractional parts. Otherwise you'll have to
read the Docs (DiGiTAL.SkReAM's opinions not withstanding).


You readers... always showing off... always reading...

quote:

ORIGINAL: anthony12345
The problem is that I'm using VBScript code on a PDA, i.e. I'm coding on my PC and uploading the code to a PDA, then checking the result


heya anthony,
Are you trying to run an excel macro on the PDA?  And if so, isn't that VBA?  Sorry if wrong, I am not very familiar with vbscript on CE.

_____________________________

"Would you like to touch my monkey?" - Dieter (Mike Meyers)

"It is better to die like a tiger, than to live like a pussy."
-Master Wong, from Balls of Fury

(in reply to ehvbs)
 
 
Post #: 11
 
 RE: Timer in VB Script - 10/12/2006 3:34:01 AM   
  anthony12345

 

Posts: 5
Score: 0
Joined: 10/10/2006
Status: offline
Thanks to both ehvbs and Digital Scream for the answers...

Unfortunately macros don't work on Excel Mobile (for PDAs) which means i had to go for other softwares...

I guess I'll just use a stopwatch!!! BAck to the roots!

Cheers

Anthony


(in reply to DiGiTAL.SkReAM)
 
 
Post #: 12
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Timer in VB Script Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts