Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to create a loop around a case statment

Status
Not open for further replies.

kdjonesmtb2

Technical User
Nov 19, 2012
93
US
Hello

I would like create a loop that will cycle through up to 12 occurrences of the following field

I am not sure what the correct syntax is for building a next loop around the code below

Select Case dt_cptsearchtext' & cstr(iCheck2)
Case "0762","0729"
If DT_servicecode ="Medical" Then

Reporter.ReportEvent 0, "Compare Medical Code - CPT Code", "Passed CPT Code in Health Trio and QNXT match; Test Case=[" & DT_Test_Case &"]; Health Trio=[" & dt_cptsearchtext & cstr (iCheck2) & "]; QNXT=[" & QNXT_codeid & cstr (iCheck2) & "]; QNXT Description=[ " & QNXT_Description1 & "]" 'This code adds CPT code and CPT description to the Report Event screen

End if


Case "", ""
If DT_servicecode="Medical" Then
Reporter.ReportEvent 1, "Compare Medical Code - CPT Code", "Failed CPT in Health Trio and QNXT - Codes Required!; Test Case=[" & DT_Test_Case &"]; Health Trio =[" & dt_cptsearchtext & cstr (icheck2) & "]; QNXT=[" & QNXT_codeid & cstr (icheck2) & "]" 'This code adds CPT code and CPT description to the Report Event screen
End If






End Select


Thanks!
 
Again, have a look at the Eval function.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
The eval function does not accomplish what I need to do

The 12 occurrences of cptsearchtext have unique values coming from a Qtp data table

I want to loop thru the table 1 to 12 and have each unique value go through the case statement
 
The 12 occurrences of cptsearchtext have unique values coming from a Qtp data table

But you didn't show any code that refers to a table. Also, showing the code where you are assigning values to dt_cptsearchtext1, dt_cptsearchtext2, dt_cptsearchtext3, etc. would be helpful.
 
The eval function does not accomplish what I need to do
Which code did you try ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Hello

Attached is some additional code from the QTP testing tool from HP which allows the use of a Datatable which is basically a spreadsheet that contains rows and columns of test data

Dim iCptQuantity 'declare variable for holding qty
iCptQuantity = CINT(DataTable.Value("cptsearchtextcount","Global")) 'pull variable from data table (cast to int)
Dim iCheck2
For iCheck2 = 1 to iCptQuantity 'loop through all possible DXsearch texts
' note in the code below, we build a string to dynamically refer to the DXearchtextX field

print icheck2
print iCptQuantity




'Updated by test maintenance run
Browser("Home").Page("HealthTrio connect - Add_16").WebEdit("cptsearchtext" ).Set DataTable.Value("cptsearchtext" & cstr(iCheck2),"Global")
 
It's difficult to piece together what you want from the fragments provided so far, and I'm not fammiliar with the data table / QTP objects etc, but I will take a stab at it:

Code:
Dim dt_cptsearchtext, DT_Test_Case, QNXT_codeid, QNXT_Description
Dim iCptQuantity 
iCptQuantity = CINT(DataTable.Value("cptsearchtextcount","Global")) 'pull variable from data table (cast to int)
Dim iCheck2
For iCheck2 = 1 to iCptQuantity
   [COLOR=blue]dt_cptsearchtext = DataTable.Value("cptsearchtext" & cstr(iCheck2),"Global")
   DT_Test_Case = ????
   QNXT_codeid = ????
   QNXT_Description = ????[/color]

   Select Case dt_cptsearchtext
      Case "0762","0729"
         If DT_servicecode ="Medical" Then
            Reporter.ReportEvent 0, "Compare Medical Code - CPT Code", _
               "Passed CPT Code in Health Trio and QNXT match; " & _
               "Test Case=[" & DT_Test_Case & "]; " & _
               "Health Trio=[" & dt_cptsearchtext & "]; " & _
               "QNXT=[" & QNXT_codeid & "]; " & _
               "QNXT Description=[ " & QNXT_Description & "]" 'This code adds CPT code and CPT description to the Report Event screen
         End if

      Case Else
         If DT_servicecode="Medical" Then
            Reporter.ReportEvent 1, "Compare Medical Code - CPT Code", _
               "Failed CPT in Health Trio and QNXT - Codes Required!; " & _
               "Test Case=[" & DT_Test_Case & "]; " & _
               "Health Trio =[" & dt_cptsearchtext & "]; " & _
               "QNXT=[" & QNXT_codeid & "]" 'This code adds CPT code and CPT description to the Report Event screen
         End If
   End Select
Next

At each iteration, gather info from the variables you need and execute your "select" statement. Of course, fill in the ????'s with the appropriate values.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top