Nested IF problem [1]

Nested IF problem

Monday, January 11, 2016 10:53 AM - Allen Liu

Hi,

I want to use nested IF to judge which mode I am.
I input "enter" first
If I got prompt "% ", enter "cli" to change mode
else if I got prompt "> ", enter "configure" to change mode
else if I got prompt "# ", enter "exit" twice to exit mode

I always got the dialog prompt "LINE#10: need 'End' "
######################################
sub main
xsh.screen.send "" &vbCr
if xsh.screen.waitforstring ("% ") = true Then
xsh.session.sleep "100"
xsh.screen.send "cli" &vbcr
else
if xsh.screen.waitforstring ("> ") = true Then
xsh.session.sleep "100"
xsh.screen.send "configure" &vbcr
end if
else
if xsh.screen.waitforstring ("# ") = true Then
xsh.session.sleep "100"
xsh.screen.send "exit" &vbcr
xsh.session.sleep "100"
xsh.screen.send "exit" &vbcr
end if
end if
end sub
######################################


Then I marked comment on 2nd else
######################################
sub main
xsh.screen.send "" &vbCr
if xsh.screen.waitforstring ("% ") = true Then
xsh.session.sleep "100"
xsh.screen.send "cli" &vbcr
else
if xsh.screen.waitforstring ("> ") = true Then
xsh.session.sleep "100"
xsh.screen.send "configure" &vbcr
end if
'else
' if xsh.screen.waitforstring ("# ") = true Then
' xsh.session.sleep "100"
' xsh.screen.send "exit" &vbcr
' xsh.session.sleep "100"
' xsh.screen.send "exit" &vbcr
' end if
end if
end sub
######################################

No dialog prompt show again but script doesn't work.

And I can't find any related script example in the internet.

Thanks if any help

Program Ver. : Xshell 5


Re: Nested IF problem

Thursday, January 14, 2016 9:46 PM - Support

The xsh.screen.waitforstring function has no return value. Instead you can use the xsh.screen.waitforstrings(plural type) function. This function can wait for several strings and it returns a value for each.

Here is a sample script:

Sub Main
Dim waitStrs
Dim result

xsh.screen.send vbCr

waitStrs = Array("% ", "> ", "# ") '% = 1, > = 2, # = 3
result = xsh.Screen.WaitForStrings(waitStrs, 0)

xsh.session.sleep(100)

select case result
case 1
xsh.screen.send "cli" &vbcr
case 2
xsh.screen.send "configure" &vbcr
case 3
xsh.screen.send "exit" &vbcr
xsh.session.sleep "100"
xsh.screen.send "exit" &vbcr
end select
End Sub

Technical Support

Like us on Facebook
Follow us on Twitter
Visit our blog Blog


Previous views: 104