I am having trouble executing if else statement in vba for secure crt, it seems the statement if is not being understood by the complier.
I wrote a code so that I could login in using host name "ABCDE" and if I get an error message saying that the host name is incorrect then I will login in using the host ip
crt.Screen.Send "ssh 22008130@ABCDE" & Chr(13)
If
Crt.Screen.WaitForString ("ssh: ABCDE: Temporary failure in name resolution",10) = True
crt.Screen.Send "ssh [email protected]" & Chr(13)
crt.Screen.WaitForString "Password:"
crt.Screen.Send "Asdf@123" & chr(13)
crt.Screen.Send "exit" & chr(13)
Else If
crt.Screen.WaitForString "Password:"
crt.Screen.Send "Asdf@123" & chr(13)
crt.Screen.WaitForString"ABCDE#"
crt.Screen.Send "exit" & chr(13)
end if
end sub
Microsoft VBScript compilation error
Error: Syntax error
File: C:\Users\22005873\Desktop\Data for script Script for Sfp
DATA\SFPSCRIPT FORERRORINNAME.vbs
Line: 9
There are a few problems in the code:
IfneedsThenYou are missing a
Then. The correct syntax as described in the documentationElse If<>ElseIfAgain, refer to the documentation. In this case, within the
Elseblock there is a newIfblock that is missing aThenand anEnd If.Presumably the correct syntax in this case is
ElseIfToo much newlines
VBScript syntax is line delimited. That means you have to put the
If condition Thenon a single line.No indentation
The compiler/interpreter doesn't care about indentation, but us mere humans need indentation to be able to follow the code. Using indentation correctly will help you spot syntax mistakes, like missing an
End If.