QTP vb scripting timer function & tips

By | June 12, 2009

QTP vb scripting timer function:
Hi Friends I am going to share one another qtp vb script function with you and one advance tips of of QTP that you will find very helpful.

Following function (CallTimeSeconds) will give you time duration of your qtp script execution in seconds.You can modify this function if you want time duration in minutes.
————————————————
Function CallTimeSeconds(StartTime,EndTime)
StartHour = Hour(StartTime)
StartMin = Minute(StartTime)
StartSec = Second(StartTime)
EndHour = Hour(EndTime)
EndMin = Minute(EndTime)
EndSec = Second(EndTime)
StartingSeconds = (StartSec + (StartMin * 60) + (StartHour * 60))
EndingSeconds = (EndSec + (EndMin * 60) + (EndHour * 60))
CallTimeSeconds = EndingSeconds – StartingSeconds
End Function
————————————————-
Now write following line at the start of your qtp script.
StartTime = Now ‘This command will give you present system time.
then write Following lines at end of your qtp script.
EndTime = Now
TimeDiff = CallTimeSeconds(StartTime,EndTime)
msgbox TimeDiff ‘You will get time duration in this message box.
—————————————————
You can modify this script according to your needs and requirements.You are always welcome to if you find any issue with qtp.

I have already share one tips with you now I am going to share one another tips and tricks.
QTP tips and tricks-2:
If you want to get host name (machine name) of your machine at run time at which qtp is installed.
You can get it programmatically through qtp.
Just write following line in your script.
——————————————————–
Set WshSystemEnv = WshShell.Environment(“USER”)
machine = WshSystemEnv(“machine name”)
——————————————————-
If you have any tips and tricks of QTP you can also share with us.

If you like this article, You can subscribe through mail.

3 thoughts on “QTP vb scripting timer function & tips

  1. qualityking

    hey dude, there’s a bug with your CallTimeSeconds function

    MsgBox CallTimeSeconds (“01:50:10″,”01:51:10”)

    this above will give you 60 (i assume this as second)

    MsgBox CallTimeSeconds (“01:50:10″,”02:50:10”)

    this call will also give you the number 60 (you need to either convert this to seconds)

    Reply
  2. Neelkanth

    Hi qualityking,

    Thanks a lot for pointing out error in this script.

    In above CallTimeSeconds function,Hour was not converted to seconds.

    Following is the modified script,

    >>>>>>>>Modified script>>>>>>>>>>>
    Function CallTimeSeconds(StartTime,EndTime)
    StartHour = Hour(StartTime)
    StartMin = Minute(StartTime)
    StartSec = Second(StartTime)
    EndHour = Hour(EndTime)
    EndMin = Minute(EndTime)
    EndSec = Second(EndTime)
    StartingSeconds = (StartSec + (StartMin * 60) + (StartHour * 3600))

    EndingSeconds = (EndSec + (EndMin * 60) + (EndHour * 3600))
    CallTimeSeconds = EndingSeconds – StartingSeconds
    End Function

    -Neelkanth

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *