Custom Search

Friday, May 6, 2011

Retrive multiple column and Rows values from Excel sheet with Query

myarray=GetDataFromExcel("C:\QTPExcelTest\Excel.xls","WCH","ColName1,ColName2","VisitGroup='Prenatal Visit'")
RowCount=UBound(myarray,2)
colVal=0
For c=0 to colVal
   For r=0 to RowCount
       MsgBox myArray(r,c)
   Next
Next

Function GetDataFromExcel(strPath, strSheet, strRqfields,strWhereClause)
Dim cn
''Create connection to Excel 2003 sheet
Set cn = CreateObject("ADODB.Connection")
cn.Provider = "Microsoft.Jet.OLEDB.4.0"
cn.ConnectionString = "Data Source="&strPath&";" &"Extended Properties=Excel 4.0;"
cn.Open
If err.number <> 0 Then
   Print Err.number
End if
''' Execting Query
Query = "Select "& strRqfields &" FROM [" & StrSheet & "$] where "& strWhereClause
Set rs = CreateObject("ADODB.recordset")
Set rs = cn.Execute(Query)
If Not Rs.EOF Then
   myArray = Rs.GetRows()
End If
GetDataFromExcel=myArray
rs.close
Set rs = Nothing
cn.Close
Set cn = Nothing
End Function

Sunday, January 9, 2011

How to add all array values without using “&” symbol?

Using Join method, add all array value to one string as below.

Dim Mystring
Dim Myarray(2)
Myarray(0)="Mr."
Myarray(1)="Jhon"
Myarray(2)="Deo"

Mystring=join(Myarray)
msgbox Mystring

Difference between Smoke and Sanity Testing?

Smoke Testing : - Smoke Testing done to ensure that whether the build can be accepted for further software testing or not. Basically, it is done to check the stability of the build received for software testing.

Sanity testing : - After receiving a build with minor changes in the code or functionality, check whether it rectified the  bugs or issues and any other bugs is introduced by the changes. and also test some of the functionalities in depth to ensure that whether the requirements are met or not.

Sunday, January 2, 2011

Get the repeated character in one string

Function GetCharCount(strChar,strSearchIn)
    dim intCounter
    for intCounter = 1 to len(strSearchIn)
         if Mid(strSearchIn,intCounter,1)=strChar then
             GetCharCount=GetCharCount+1
         end if
    next
End Function
msgbox GetCharCount("s", "this is a string")

======Second method=========
str="this is a string"
msgbox Len(str)-Len(Replace(str,"s",""))


Thursday, October 21, 2010

Suppose I’m having a string wipro123xyz45 I need to get the value 12345 only from the string and the string could be changed randomly

Function RegExpTest(patrn, strng)
        Dim regEx, Match, Matches ' Create variable.
        Set regEx = New RegExp ' Create a regular expression.
        regEx.Pattern = patrn ' Set pattern.
        regEx.Global = True ' Set global applicability.
        Set Matches = regEx.Execute(strng) ' Execute search.
        For Each Match in Matches ' Iterate Matches collection.
              RetStr = RetStr & Match.Value' & vbCRLF
        Next
        RegExpTest = RetStr
End Function
a=(RegExpTest("[0-9]", "wipro123xyz45"))
msgbox(a)

Wednesday, October 20, 2010

Regular expression for date formate (mm/dd/yy)

[1-9]|1[0-2]/[1-9]|[1-2][0-9]|3[0-1]/[0-9][0-9] ------12/10/99

^([1-9]|1[0-2])[-/.]([1-9][1-2][0-9]3[0-1])/[-/.](19[0-9][0-9]|20[0-9][0-9])$ ----- 12(-/.)10(-/.)1999
|  Indicates a choice between two items.

how to compare two excell sheets by using vbscript??

Set objExcel = CreateObject("Excel.application")
objExcel.Visible = True
Set objWorkbook1 = objExcel.workbooks.Open("C:\First.xls")
Set objWorkbook2 = objExcel.workbooks.Open("C:\Second.xls")
Set objWorksheet1 = objWorkbook1.worksheets(1)
Set objWorksheet2 = objWorkbook2.worksheets(1)
For Each cell In objWorksheet1.UsedRange
If cell.Value <> objWorksheet2.Range(cell.Address).Value Then
msgbox "value is different"
Else
msgbox "value is same"
End If
Next
objWorkbook1.close
objWorkbook2.close
objExcel.quit
set objExcel=nothing