Micro Focus QTP (UFT) Forums
Is there a better way to manage my If statements? - Printable Version

+- Micro Focus QTP (UFT) Forums (https://www.learnqtp.com/forums)
+-- Forum: Micro Focus UFT (earlier known as QTP) (https://www.learnqtp.com/forums/Forum-Micro-Focus-UFT-earlier-known-as-QTP)
+--- Forum: UFT / QTP Beginners (https://www.learnqtp.com/forums/Forum-UFT-QTP-Beginners)
+--- Thread: Is there a better way to manage my If statements? (/Thread-Is-there-a-better-way-to-manage-my-If-statements)



Is there a better way to manage my If statements? - mv8167 - 09-03-2011

Is there a better way to manage my If statements?

My issue is; I have 10 or so dialog boxes and depending on which I have found, I need to use the code associated with the dialog box. I have 2-5 objects that I look for to determine which dialog box that I have.

My problem; is, if the third If statement is not found, my code Exits all of my If statements.
My goal; is to have code to search each of the set of Dialog boxes until it finds the correct “complete” match.

My code:
Code:
'1 – Dialog Box
If .WebElement("WebTable_AccountNo").Exist(0) Then
    If  .WebEdit("StartDate").Exist(0) Then
        If .WebElement("mm/dd/yyyy_Start").Exist(0) Then    
             If .WebCheckBox("CheckboxSave").Exist(0) Then
                Call UseReport1
            End If
        End If
    End If
'2 – Dialog Box
ElseIf .WebElement("WebTable_AccountNo").Exist(0) Then
    If .WebRadioGroup("TradeDtRange").Exist(0) Then
        Call UseReport2
    End If
'3 -- Dialog Box
ElseIf .WebElement("WebTable_AcctType").Exist(0) Then
    If .WebElement("WebTable_CAP").Exist(0) Then
        If .WebElement("StartDate").Exist(0) Then
            Call UseReport3
        End If
    End If
'4 – Dialog Box
ElseIf .WebElement("WebTable_CAP").Exist(0) Then
    If .WebEdit("SubFirm").Exist Then
         If .WebElement("StartDate").Exist(0) Then
            Call UseReport4
        End If
    End If
'5 – Dialog Box
ElseIf .WebElement("WebTable_AccountNo").Exist(0) Then
    If .WebElement("StartDate").Exist(0) Then
        If .WebCheckBox("CheckboxSave").Exist(0) Then
            If .WebList("Select_Month").Exist Then
                       Call UseReport5
            End If
        End If
    End If
'6 – No Dialog Box
ElseIf ReportName = "ALL IMAGED CLIENT DOCUMENTS" Then
    Call UseReport6
Else
    MsgBox ("No matching Search Preference dialog box found")
End If


How can I change my code so that if I reach 1-Dialog Box’s third If statement and Fails, the code will check the next 2 –Dialog Box’s code. Or must I complete each Dialog box’s If..If..If… EndIf…EndIf..EndIf statements, etc?