VBScript Programs PART - IV
'****************************************************
'31 Trim a given string from both sides
Dim oStr
oStr=" QTP "
print trim(oStr)
'****************************************************
'****************************************************
'32 Write a program to insert 100values and to delete 50 values from an array
Dim oArray()
Dim iLoop
ReDim oArray(100)
For iLoop=0 to ubound(oArray)
oArray(iLoop)=iLoop
'Print total 100 Values
print(oArray(iLoop))
Next
print "******************************"
print "******************************"
ReDim preserve oArray(50)
For iLoop=0 to ubound(oArray)
'Print Values after deleting 50 values
print(oArray(iLoop))
Next
'****************************************************
'****************************************************
'33 Write a program to force the declaration of variables
Option explicit ' this keyword will enforce us to declare variables
Dim x
x=10
'Here we get an error because i have not declared y,z
y=20
z=x+y
print z
'****************************************************
'****************************************************
'34 Write a program to raise an error and print the error number.
On Error Resume Next
Err.Raise 6 ' Raise an overflow error.
print ("Error * " & CStr(Err.Number) & " " & Err.Description)
'****************************************************
'****************************************************
'35 Finding whether a variable is an Array
Dim oArray()
if isarray(oArray) then
print "the given variable is an array"
else
print "the given variable is not an array"
End if
'****************************************************
'****************************************************
'36 Write a program to list the Timezone offset from GMT
Dim objWMIService
Dim colTimeZone
Dim objTimeZone
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\.\root\cimv2")
Set colTimeZone = objWMIService.ExecQuery("Select * from Win32_TimeZone")
For Each objTimeZone in colTimeZone
print "Offset: "& objTimeZone.Bias
Next
'****************************************************
'****************************************************
'37 Retrieving Time Zone Information for a Computer
Dim objWMIService
Dim colTimeZone
Dim objTimeZone
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\.\root\cimv2")
Set colTimeZone = objWMIService.ExecQuery("Select * from Win32_TimeZone")
For Each objItem in colTimeZone
print "Bias: " & objItem.Bias
print "Caption: " & objItem.Caption
print "Daylight Bias: " & objItem.DaylightBias
print "Daylight Day: " & objItem.DaylightDay
print "Daylight Day Of Week: " & objItem.DaylightDayOfWeek
print "Daylight Hour: " & objItem.DaylightHour
print "Daylight Millisecond: " & objItem.DaylightMillisecond
print "Daylight Minute: " & objItem.DaylightMinute
print "Daylight Month: " & objItem.DaylightMonth
print "Daylight Name: " & objItem.DaylightName
print "Daylight Second: " & objItem.DaylightSecond
print "Daylight Year: " & objItem.DaylightYear
print "Description: " & objItem.Description
print "Setting ID: " & objItem.SettingID
print "Standard Bias: " & objItem.StandardBias
print "Standard Day: " & objItem.StandardDay
print "Standard Day Of Week: " & objItem.StandardDayOfWeek
print "Standard Hour: " & objItem.StandardHour
print "Standard Millisecond: " & objItem.StandardMillisecond
print "Standard Minute: " & objItem.StandardMinute
print "Standard Month: " & objItem.StandardMonth
print "Standard Name: " & objItem.StandardName
print "Standard Second: " & objItem.StandardSecond
print "Standard Year: " & objItem.StandardYear
Next
'****************************************************
'****************************************************
'38 Write a program to Convert an expression to a date
Dim StrDate
Dim actualDate
Dim StrTime
Dim actualTime
StrDate = "October 19, 1962" ' Define date.
actualDate = CDate(StrDate) ' Convert to Date data type.
print actualDate
StrTime = "4:35:47 PM" ' Define time.
actualTime = CDate(StrTime) ' Convert to Date data type.
print actualTime
'****************************************************
'****************************************************
'39 Display current date and Time
print now
'****************************************************
'****************************************************
'40 Find difference between two dates.
'Date difference in Years
print DateDiff("yyyy","12/31/2002",Date)
'Date difference in Months
print DateDiff("m","12/31/2002",Date)
'Date difference in Days
print DateDiff("d","12/31/2002",Date)
'****************************************************