Showing posts with label QTP/HP UFT VBScript Programs. Show all posts
Showing posts with label QTP/HP UFT VBScript Programs. Show all posts

Saturday, July 13, 2013

QTP/HP UFT VBScript Programs PART - V

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  
  '****************************************************  

 

Thursday, July 11, 2013

QTP/HP UFT VBScripts Programs PART - III

VBScript Programs PART - III

  '****************************************************  
  '21    Print all values from an Array  
  Dim oArray  
  Dim oCounter  
  oArray=array(1,2,3,4,"qtp","Testing")  
    
  For oCounter=lbound(oArray) to ubound(oArray)  
      print oArray(oCounter)  
  Next  
    
  '****************************************************  
  '****************************************************  
  '22    Sort Array elements  
  Dim oArray  
  Dim oCounter1  
  Dim oCounter2  
  Dim tmp  
    
  oArray=array(8,3,4,2,7,1,6,9,5,0)  
    
  For oCounter1=lbound(oArray) to ubound(oArray)  
    
          For oCounter2=lbound(oArray) to ubound(oArray)-1  
    
                      If oArray(oCounter2)>oArray(oCounter2+1) Then  
                          tmp=oArray(oCounter2)  
                          oArray(oCounter2)=oArray(oCounter2+1)  
                          oArray(oCounter2+1)=tmp  
                      End If  
                          
          Next  
        
  Next  
    
  For oCounter1=lbound(oArray) to ubound(oArray)  
      print oArray(oCounter1)  
  Next  
        
  '****************************************************  
  '****************************************************  
  '23    Add two 2X2 matrices  
  Dim oArray1(1,1)  
  Dim oArray2(1,1)  
  Dim tArray(1,1)  
    
  oArray1(0,0)=8  
  oArray1(0,1)=9  
  oArray1(1,0)=5  
  oArray1(1,1)=-1  
    
  oArray2(0,0)=-2  
  oArray2(0,1)=3  
  oArray2(1,0)=4  
  oArray2(1,1)=0  
    
  tArray(0,0)=oArray1(0,0)+ oArray2(0,0)  
  tArray(0,1)=oArray1(0,1)+oArray2(0,1)  
  tArray(1,0)=oArray1(1,0)+oArray2(1,0)  
  tArray(1,1)=oArray1(1,1)+oArray2(1,1)  
  '****************************************************  
  '****************************************************  
    
  '24    Multiply Two Matrices of size 2X2  
    
  Dim oArray1(1,1)  
  Dim oArray2(1,1)  
  Dim tArray(1,1)  
    
  oArray1(0,0)=8  
  oArray1(0,1)=9  
  oArray1(1,0)=5  
  oArray1(1,1)=-1  
    
  oArray2(0,0)=-2  
  oArray2(0,1)=3  
  oArray2(1,0)=4  
  oArray2(1,1)=0  
    
  tArray(0,0)=oArray1(0,0)* oArray2(0,0)+ oArray1(0,1)* oArray2(1,0)  
  tArray(0,1)=oArray1(0,0)* oArray2(0,1)+ oArray1(0,1)* oArray2(1,1)  
  tArray(1,0)=oArray1(1,0)* oArray2(0,0)+ oArray1(1,1)* oArray2(1,0)  
  tArray(1,1)=oArray1(1,0)* oArray2(0,1)+ oArray1(1,1)* oArray2(1,1)  
    
    
  '****************************************************  
  '****************************************************  
  '25    Convert a String in to an array  
    
  Dim oStr  
  Dim iLoop  
  oStr="Quick Test Professional"  
  StrArray=split(oStr)  
    
  For iLoop=0 to ubound(StrArray)  
          print StrArray(iLoop)  
  Next  
    
  '****************************************************  
  '****************************************************  
  '26    Convert a String in to an array using ‘i‘ as delimiter  
    
  Dim oStr  
  Dim iLoop  
  oStr="Quick Test Professional"  
  StrArray=split(oStr,"i")  
    
  For iLoop=0 to ubound(StrArray)  
          print StrArray(iLoop)  
  Next  
    
  '****************************************************  
  '****************************************************  
  '27    Find number of words in string  
    
  Dim oStr  
  Dim iLoop  
  oStr="Quick Test Professional"  
  StrArray=split(oStr," ")  
  print "Theere are "&ubound(StrArray)+1&" words in the string"  
    
  '****************************************************  
  '****************************************************  
  '28    Write a program to reverse the words of a given string.  
    
  Dim oStr  
  Dim iLoop  
  oStr="Quick Test Professional"  
  StrArray=split(oStr," ")  
    
  For iLoop=0 to ubound(StrArray)  
          print strreverse(StrArray(iLoop))  
  Next  
    
  '****************************************************  
  '****************************************************  
  '29    Print the data as a Pascal triangle  
  'The formulae for pascal triangle is nCr=n!/(n-r)!*r!  
    
  Dim PascalTriangleRows  
  Dim nCr  
  Dim NumCount  
  Dim RowCount  
    
  PascalTriangleRows = 10  
  For NumCount = 0 To PascalTriangleRows  
      toPrint= Space(PascalTriangleRows - NumCount)  
      For RowCount = 0 To NumCount  
              If (NumCount = RowCount) Then  
                      nCr = 1  
              Else  
                  nCr = Factorial(NumCount) / (Factorial(NumCount - RowCount) * Factorial(RowCount))  
              End If  
       toPrint=toPrint&nCr&" "  
      Next  
      print toPrint  
  Next  
    
    
  Function Factorial(num)  
     Dim iLoop  
      Factorial = 1  
      If num <> 0 Then  
          For iLoop = 2 To num  
              Factorial = Factorial * iLoop  
          Next  
      End If  
  End Function  
  '****************************************************  
  '****************************************************  
  '30    Join elements of an array as a string  
    
  Dim oStr  
  Dim iLoop  
  oStr="Quick Test Professional"  
  StrArray=split(oStr," ")  
    
  print join(StrArray," ")  
    
  '****************************************************