13 years ago
VBScript For Loop
I’m writing this vbscript in a in testcomplete.
I’m having trouble with a loop… I don’t know if I need an If…else..
The script has a ADO connection that looks at a table in the database, I need it to populate fields in a program from that database table.
My for loop fills the first Row/entry correctly. But it seems that it just loops back to the first Row/Entry, it doesn’t move on to the second Row/entry in the table. I’m wondering what I need to add to the first for loop?
'Sales Rep Maintenance
'Adding New Rep
'USEUNIT Seek
Dim txtServer, testCtrlDBase
txtServer = ProjectSuite.Variables.ServerName
testCtrlDBase = ProjectSuite.Variables.TestControlDB
Sub Test1
Dim FirstName,LastName,Organization,CommissionType,CommissionRate,FixedFee,SafariUser
Dim control
Dim control2 ‘These aren’t being called / used
Dim control3 ‘These aren’t being called / used
Dim MyServer
Dim MyDataBase
Dim TypeID
Dim h,i
TypeID = 1
MyServer = "ENSQL2005"
MyDataBase = "SAF416Pete"
Call Aliases.Explorer.wndShell_TrayWnd.ReBarWindow32.MSTaskSwWClass.ToolbarWindow32.CheckItem("EnSite Safari Suite®", True, False)
SeekScreen ("SalesAdmin.ucSalesRepMaint")
Set control = Aliases.Sys.Safari.FormHost.MDIClient.FLC_SalesRepMX.FLP_SalesRepMX.LCC_SalesRepMX.Embedded.vseContainer
Set AConnection = ADO.CreateConnection
AConnection.ConnectionString = "Driver={SQL Server};Server=" + MyServer + ";Database=" + MyDataBase + ";Uid=SafariUser;Pwd=safari"
AConnection.Open
Set Cmd = ADO.CreateCommand
Cmd.ActiveConnection = AConnection
Cmd.CommandText = "Exec qa_SelectSalesRepData " & TypeID ‘stored procedure qa_SelectSalesRepData
Cmd.CommandType = adCmdText
Set RecSet = Cmd.Execute
RecSet.MoveFirst
For h = 0 to RecSet.Fields.Count -1 ‘Loop in question Trying to retrieve another name from the database Table
control.keys("~N")
For i = 0 to RecSet.Fields.count -1
Select Case RecSet.Fields(i).name
Case "FirstName"
control.txtFirst.SetText(RecSet.Fields(i).value)
Case "LastName"
control.txtLast.setText(RecSet.Fields(i).value)
Case "Organization"
control.txtOrganization.SetText(RecSet.Fields(i).value)
Case "CommissionType"
control.cboCommissionType.ClickItem(RecSet.Fields(i).value)
Case "CommissionRate"
control.txtCommissionRate.SetText(RecSet.Fields(i).value)
Case "FixedFee"
control.txtFixedFee.SetText(RecSet.Fields(i).value)
Case "SafariUser"
control.cboSafariUser.ClickItem(RecSet.Fields(i).value)
Case else
Log.Message "Need coding to handle " & RecSet.Fields(i).name & " and " & RecSet.Field(i).value &" for Test1: "
End Select
Next
control.keys("~S")
Next
End Sub