VBScript Programs PART - V
'****************************************************
'41 Add time interval to a date
print DateAdd("m", 1, "31-Jan-95")
'****************************************************
'****************************************************
'42 Print current day of the week
Print day(date)
'****************************************************
'****************************************************
'43 Find whether current month is a long month
Dim oCurrentMonth
Dim ocurrentYear
Dim oDaysinMonths
oCurrentMonth = Month(date)
ocurrentYear = Year(date)
oDaysinMonths=Day(DateSerial(ocurrentYear, oCurrentMonth + 1, 0))
print oDaysinMonths&" Days in Current Month"
If oDaysinMonths=31 Then
print "Current Month is a long month"
else
print "Current Month is not a long month"
End If
'****************************************************
'****************************************************
'44 Find whether given year is a leap year
'1st Method
'The rules for leap year:
'1. Leap Year is divisible by 4 (This is mandotory Rule)
'2. Leap Year is not divisible by 100 (Optional)
'3. Leap Year divisble by 400 (Optional)
Dim oYear
oYear=1996
If ((oYear Mod 4 = 0) And (oYear Mod 100 <> 0) Or (oYear Mod 400 = 0)) then
print "Year "&oYear&" is a Leap Year"
else
print "Year "&oYear&" is not a Leap Year"
End If
'45. 2nd Method
' Checking 29 days for February month in specified year
Dim oYear
Dim tmpDate
oYear=1996
tmpDate = "1/31/" & oYear
DaysinFebMonth = DateAdd("m", 1, tmpDate)
If day(DaysinFebMonth )=29 then
print "Year "&oYear&" is a Leap Year"
else
print "Year "&oYear&" is not a Leap Year"
End If
'****************************************************
'****************************************************
'46 Format Number to specified decimal places
Dim oNum
Dim DecimaPlacestobeFormat
oNum = 3.14159
DecimaPlacestobeFormat=2
print Round(oNum , DecimaPlacestobeFormat)
'****************************************************
'****************************************************
'47 Write a program to Generate a Random Numbers
'This script will generate random numbers between 10 and 20
Dim rStartRange
Dim rEndRange
rStartRange=10
rEndRange=20
For iLoop=1 to 10
print Int((rEndRange - rStartRange + 1) * Rnd + rStartRange)
Next
'****************************************************
'****************************************************
'48 Write a program to show difference between Fix and Int
'Both Int and Fix remove the fractional part of number and return the resulting integer value.
'The difference between Int and Fix is that if number is negative, Int returns the first negative integer less than or equal to number,
'whereas Fix returns the first negative integer greater than or equal to number.
'For example, Int converts -8.4 to -9, and Fix converts -8.4 to -8.
print Int(99.8) ' Returns 99.
print Fix(99.2) ' Returns 99.
print Int(-99.8) ' Returns -100.
print Fix(-99.8) ' Returns -99.
print Int(-99.2) ' Returns -100.
print Fix(-99.2) ' Returns -99.
'****************************************************
'****************************************************
'49 Write a program to find subtype of a variable
Dim oVar
Dim oDatatypes
oVar="QTP"
oVartype=Typename(oVar)
print oVartype
'****************************************************
'****************************************************
'50 Write a program to print the decimal part of a given number
Dim oNum
oNum=3.123
oDecNum=oNum- int(oNum)
print oDecNum
'****************************************************
No comments:
Post a Comment