by admin | Mar 10, 2016 | 2016 |
please put a short text here please put a short text here please put a short text here please put a short text here please put a short text here
Comparing dates and times
Dim dtDate1_dtDate1=Cdate("08/01/2009 12:00AM")
Dim dtDate2_dtDate2=Cdate("08/01/2009 12:00AM")
Dim dateTime:Set dateTime=DotNetFactory.CreateInstance("System.DateTime")
Msgbox dateTime.Compare(strDate1,strDate2)
'If dates are equal, then result will be 0.
Parsing String Representation of a date
Dim dateTime:Set dateTime=DotNetFactory.CreateInstance("System.DateTime")
Msgbox dateTime.Parse("Dec 03, 2003 12:00:00 PM")
'The output will be 12/3/2003 12:00:00 PM
Checking whether the year is leap year or not
Msgbox dateTime.IsLeapYear(1997)
'It will return True, if the year is a leap year else false.
Adding and Subtracting days
Dim dateTime:Set
dateTime=DotNetFactory.CreateInstance("System.DateTime","",1996,8,3)
'The date is set while creating DateTime insyance with three constructors
(year,month & day)
Msgbox dateTime.AddDays(2)'Adding two days
Msgbox dateTime.AddDays(-1)'Subtracting one day
Formatting a date
Dim dateTime:Set dateTime=DotNetFactory.CreateInstance("System.DateTime")
Msgbox dateTime.Now.ToString("MMM ddd d HH:mm yyyy")
Getting Short and Long Date
Msgbox dateTime.Now.ToLongDateString()'Long date
Msgbox dateTime.Now.ToShortDateString()'Short date
Displaying AM or PM FROM a date
Msgbox dateTime.Now.ToString("tt ")
'The output will be AM or PM
by admin | Mar 10, 2016 | 2016 |
Sometimes we need to know which is step being executed currently by QTP. Using
automatic timeout message box, we can get that information, but QTP execution is
halted until the message box timeout expires. How to display some useful runtime
information without halting the execution? The only workaround is displaying tool tip
information in Windows System Tray. Let us see how this technique is done using DOT
Net Factory.
Code
Class BalloonTooltipClass
Private oNtfy,oToolTip,oIcon,icon_Path
Private sub Class_Initialize
icon_Path="C:sample.ico"
Set
oNtfy=DotNetFactory.CreateInstance("System.Windows.Forms.NotifyIcon","System.Windo
ws.Forms")
Set oToolTip
=DotNetFactory.CreateInstance("System.Windows.Forms.ToolTipIcon","System.Windows.F
orms")
Set
oIcon=DotNetFactory.CreateInstance("System.Drawing.Icon","System.Drawing",icon_Pat
h)
End Sub
Function Show(ByVal strTitle,ByVal strContent)
oNtfy.Icon=oIcon
oNtfy.BalloonTipIcon=oToolTip.Info
oNtfy.Visible=True
oNtfy.Text = strTitle
oNtfy.BalloonTipTitle = strTitle
oNtfy.BalloonTipText=strContent
oNtfy.ShowBalloonTip(5000)
End Function
Private Sub Class_Terminate
oNtfy.Dispose()
Set oIcon =Nothing
Set oTool =Nothing
Set oNtfy=Nothing
End Sub
End Class
Public BalloonTooltip:Set BalloonTooltip=New BalloonTooltipClass
BalloonTooltip.Show "test title","test content"
wait(15)
by admin | Mar 10, 2016 | 2016 |
How to get Desktop, MyDocuments, ProgramFiles & Temp directories path at runtime?
This is possible using DotNetFactory and WScript.
DotNetFactory
Function GetDirectoryPath(ByVal strDirName)
Dim oSpecialDir
Set oSpecialDir=DotNetFactory.CreateInstance("Microsoft.VisualBasic.FileIO.SpecialDirectories","Microsoft.VisualBasic")
Execute "GetDirectoryPath=oSpecialDir."&strDirName
Set oSpecialDir=Nothing
End Function
Msgbox GetDirectoryPath("Desktop")
WScript
Dim WSHShell:Set WSHShell = CreateObject("WScript.Shell")
Msgbox WSHShell.SpecialFolders("Desktop")
by admin | Mar 10, 2016 | 2016 |
StringDictionary is a Hash Table; it is designed to accept only strings. It could be used to handle large amounts of strings and retrieves item very quickly since it is a Hash Table. Let us see how we can add items to the StringDictionary object and retrieve it.
Code
Dim oStringDict
Set oStringDict=DotNetFactory.CreateInstance("System.Collections.Specialized.StringDictionary")
oStringDict.Add "City1","London"
oStringDict.Add "City2","Paris"
Msgbox oStringDict.Item("City1")
Set oStringDict=Nothing
Tags
Dictionary Object, .net StringDictionary