time in miliseconds

1,363 views
Skip to first unread message

Vikas

unread,
Mar 7, 2007, 9:08:02 AM3/7/07
to QTP - Mercury QuickTest Professional - Automated Software Testing
Hi
Is there any way that I can get the time in miliseconds in vb
script??

Regards
Vikas

Mohit Gupta

unread,
Mar 7, 2007, 9:16:15 AM3/7/07
to Mercu...@googlegroups.com
Vikas,
I second = 1000 milliseconds
U could use it just like that,i.e, multiply the no of seconds with 1000 and get milliseconds.
If u are looking for something more specific, pls specify.
Thanks

 
--
Mohit Gupta
"Have a wonderful day!"

Shirish K

unread,
Mar 7, 2007, 9:16:27 AM3/7/07
to Mercu...@googlegroups.com
Check this function
 Function PrintInterval(byVal dblMilliSecond)
    Dim intMilliSecond, intSeconds, intMinute, intHour
  
    intMilliSecond = Int(dblMilliSecond*1000) mod 1000
  
    intSecond = Int(dblMilliSecond)
  
    intMinute = Int(intSecond / 60)
  
    intSecond = intSecond mod 60
  
    intHour = Int(intMinute / 60)
  
    intMinute = intMinute mod 60
  
    PrintInterval = intHour &" hours " & _
                    intMinute &" minutes " & _
                    intSecond &" seconds " & _
                    intMilliSecond &" milliseconds"  
  End Function
 
OR
Sending you pasted article from one of site. Check if this is helpful for you.
 
Obtaining Milliseconds in VBScript? [VBScript]

(Monday, 11 October 2004) - Written by Paul McKinney - Last Updated (Tuesday, 12 October 2004)

Many of the application I work on capture data at a high rate of speed. I am working on an application that captures data

from a PLC into a SQL Server database, then I copy the data to another database. For various reasons I decided that I

would need to do this with VBScript. When I copied the data I wanted to make sure I didn?t loose the milliseconds from

the datetime stamp.

You may be aware that none of the formatting functions within VBScript will display the milliseconds. Dates are stored in

what is called a vardate format. The vardate is really just a Double. A value of 0.0 is January 1, 1900 12:00 AM, a value

of 1.0 is January 2, 1900 12:00 AM, and a value of 1.5 is January 2, 1900 12:00 noon. So I started doing the math. I

thought I could easily calculate the milliseconds from the Double. My ingenious code looked something like this.

dim ms1

d = cdate(now)

ms1 = fix( (cdbl(d) - fix(cdbl(d))) * 86400000.0 ) - (hour(d)*60*60*1000 + minute(d)*60*1000 + second(d) * 1000)

I would chop off the fraction then calculate the milliseconds in the current day from the Double. Then using the

information VBScript gives me I would calculate the milliseconds up to the hour, minute, and second. If I subtracted the

two I would get the number of milliseconds remaining, Right? Wrong?

You?ll never guess what I got? 0. That?s right. Even in the Double value VBScript does not hold the precision out to the

millisecond. Oh well. Back to the drawing board



On 3/7/07, Vikas <vika...@gmail.com> wrote:

Dmitry Motevich

unread,
Mar 7, 2007, 9:55:24 AM3/7/07
to Mercu...@googlegroups.com
Try the following code:

sNow = Now
sYear = Year(sNow)
sMonth = Month(sNow)
sDay = Day(sNow)
sHour = Hour(sNow)
sMinute = Minute(sNow)
sSecond = Second(sNow)
sMilliSecond = Timer * 1000 mod 1000

sFullDateTime = sYear & "." & sMonth & "." & sDay & " " & sHour & ":" & sDay &":" & sSecond & "." & sMilliSecond
MsgBox sFullDateTime

Result ("2007.3.7 17:7:6.296") is attached.
If you need, you can add leading zeros... It will look marvellously :)



On 3/7/07, Vikas <vika...@gmail.com> wrote:



--
Dmitry Motevich
millis.jpg

Shawn Bower

unread,
Mar 7, 2007, 10:37:12 AM3/7/07
to Mercu...@googlegroups.com
To time to millisecond accuracy you need to use a little known VBScript function called, of all things, Timer(). The Timer() function returns the number of milliseconds between 00:00 (12:00 AM Midnight) and the time it's called.

For example:

dblTimer = Timer()

Im guessing you want this to be able to seed a random function in which case you dont really need to format you can just use the raw data.

Shawn

namita d

unread,
Mar 8, 2007, 3:39:34 AM3/8/07
to Mercu...@googlegroups.com

Hi,

Thanks Shirish for helping me......for being so patient.
The problem of my script recording PS-1, PS-2 ,PS-3 to PS got solved by
changing the settings .
Tools>options>Web>Page/Frames option>Select Radio button different test obj
description. for both PAGE & FRAME.Also a webtable is to be added exactly
below page P S

And the following code for

Dim NumRow
NumRow=Browser("P S").Page("P S").WebTable("First Name").GetROProperty
("rows")


'If the items are present in List

if NumRow<>1 Then

'checkbox on
Browser("P S").Page("P S").WebCheckBox("ctl00$ContentPlaceHolder1$Data").Set
"ON"

'Click DELETE button
Browser("P S").Page("P S").WebButton("Delete").Click

'Do you want to Delet click Yes
Browser("P S").Dialog("Microsoft Internet Explorer").WinButton("OK").Click
else

'Log out of screen
Browser("P S").Page("P S").Link("Log Out").Click
End if

Browser("P S").Dialog("Microsoft Internet Explorer").WinButton("OK").Click

_________________________________________________________________
Palate teasers: Straight from Master Chef Sanjeev Kapoor
http://content.msn.co.in/Lifestyle/Moreonlifestyle/LifestylePT_101106_1530.htm

Reply all
Reply to author
Forward
0 new messages