Micro Focus QTP (UFT) Forums
Why I need more then one End If ? - 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: VB Scripting/Descriptive Programming (https://www.learnqtp.com/forums/Forum-VB-Scripting-Descriptive-Programming)
+--- Thread: Why I need more then one End If ? (/Thread-Why-I-need-more-then-one-End-If)



Why I need more then one End If ? - nidhitaneja - 02-27-2014

Hello experts, I am new to IT and trying to learn to script but unable to understand why I need EndIf four times in below script at the end for it to work. I have been writing other ElseIf statements and used EndIf only once at end of script and they worked fine but this one is requiring it 4 times. ??

Quote:Dim State, Region
State=Inputbox ("Enter a State")
Region=Inputbox ("Enter a Region")

If state= "AP" Then
If Region= "Telangana" Then
msgbox "Hello Reddy"
msgbox "Dist count is 10"

Else if Region= "Rayalasema" Then
msgbox "Hello GCR"
msgbox "Dist count is 4"

Else If Region= "Costal" Then
msgbox "Hello mohan"
msgbox "Dist count is 9"

End If
End If
End If
End If



RE: Why I need more then one End If ? - supputuri - 02-27-2014

ElseIf should be one word (without space)....


RE: Why I need more then one End If ? - nidhitaneja - 02-27-2014

Thanks Supputuri ji.

Also, Please tell me why needed EndIf 4 times at end ? Thanks.


RE: Why I need more then one End If ? - supputuri - 02-27-2014

Actually we dont need 4 End If, check the below code.
PHP Code:
Dim StateRegion
State
=Inputbox ("Enter a State")
Region=Inputbox ("Enter a Region")
If 
state"AP" Then
    
If Region"Telangana" Then
        msgbox 
"Hello Reddy"
        
msgbox "Dist count is 10"
    
Elseif Region"Rayalasema" Then
        msgbox 
"Hello GCR"
        
msgbox "Dist count is 4"
    
ElseIf Region"Costal" Then
        msgbox 
"Hello mohan"
        
msgbox "Dist count is 9"
    
End If
End If