VB script using qtp / uft and MSExcel connection string
Here is the connection string between qtp and excel
Option Explicit
Dim conn,recordSet
Dim strRoll, strMarks
Set conn=CreateObject("ADODB.Connection")
Set recordSet=CreateObject("ADODB.Recordset")
Dim strConnectionString,strQuery
strConnectionString="Provider=Microsoft.ACE.OLEDB.12.0; Data Source=""D:\Data\OrderData.xlsx"";Extended Properties=""Excel 12.0 Xml;HDR=Yes;"";"
conn.open strConnectionString
strQuery="select * from [result$]"
recordSet.open strQuery,conn
If not(recordSet.EOF) Then
recordSet.movefirst
While not(recordSet.EOF)
strRoll=recordSet(0)
strMarks=recordset(2)
Dim status
status=Check_result(strRoll,strMarks)
' msgbox (status)
strUpdate="update[result$] Set Res='Pass' where RollNo="&strRoll
If status="Pass" Then
conn.executeQuery(strUpdate)
else
strUpdate="update[result$] Set Res='Fail' where RollNo="&strRoll
conn.execute(strUpdate)
End If
recordSet.moveNext
Wend
recordSet.close
conn.close
End If
QTP regular expression example
Here is the connection string between qtp and excel
Option Explicit
Dim conn,recordSet
Dim strRoll, strMarks
Set conn=CreateObject("ADODB.Connection")
Set recordSet=CreateObject("ADODB.Recordset")
Dim strConnectionString,strQuery
strConnectionString="Provider=Microsoft.ACE.OLEDB.12.0; Data Source=""D:\Data\OrderData.xlsx"";Extended Properties=""Excel 12.0 Xml;HDR=Yes;"";"
conn.open strConnectionString
strQuery="select * from [result$]"
recordSet.open strQuery,conn
If not(recordSet.EOF) Then
recordSet.movefirst
While not(recordSet.EOF)
strRoll=recordSet(0)
strMarks=recordset(2)
Dim status
status=Check_result(strRoll,strMarks)
' msgbox (status)
strUpdate="update[result$] Set Res='Pass' where RollNo="&strRoll
If status="Pass" Then
conn.executeQuery(strUpdate)
else
strUpdate="update[result$] Set Res='Fail' where RollNo="&strRoll
conn.execute(strUpdate)
End If
recordSet.moveNext
Wend
recordSet.close
conn.close
End If
QTP regular expression example
Option explicit
SystemUtil.CloseProcessByName "iexplore.exe"
Dim str1(3),MyReg,u,i
str1(0)="np2012"
str1(1)="ww76789"
str1(2)="gg876287"
For i=0 to 2
Set myReg=new regexp
myReg.Pattern="[np|ww|gg]{2}[0-9]{4,6}"
myReg.ignorecase=true
u=myReg.test(str1(i))
If u Then
print "pass"
else
print "fail"
End If
Next
SystemUtil.CloseProcessByName "iexplore.exe"
Dim str1(3),MyReg,u,i
str1(0)="np2012"
str1(1)="ww76789"
str1(2)="gg876287"
For i=0 to 2
Set myReg=new regexp
myReg.Pattern="[np|ww|gg]{2}[0-9]{4,6}"
myReg.ignorecase=true
u=myReg.test(str1(i))
If u Then
print "pass"
else
print "fail"
End If
Next
No comments:
Post a Comment