vbscriptexitcrt

Exit a Secure CRT script without clossing the application or session


I am using a vbscript via Secure CRT, containing different subs as well as global variables, outside the main sub, in order to be available for the subs.

I would like to ask if there is a way of exiting the script at any point desired, before reaching the end of the process and without using crt.Quit, because it would be better to have secure crt running and available for additional commands.

My sript is as follows

Intro = msgbox ("ONLY FOR AUTHORISED USE!!!", 1+16+0+4096)
    If Intro =2 Then
        MsgBox"Operation Cancelled"
    ThisIsTheEnd
    End If

DSLAM=inputbox ("Please Enter Dslam Name","Login")
    If DSLAM="" Then
        MsgBox"Operation Cancelled"
    ThisIsTheEnd
    End If

crt.Screen.Send "telnet " &  DSLAM & Chr(13)
crt.Screen.WaitForString "login:"
crt.Screen.Send "xxxx" & Chr(13)
crt.Screen.WaitForString "Password:"
crt.Screen.Send "xxxxxxxx" & Chr(13)
crt.Screen.WaitForString ">"
crt.Screen.Send "enable" & Chr(13)
crt.Screen.WaitForString "Password:"
crt.Screen.Send "xxxxxxxx" & Chr(13)
crt.Screen.WaitForString "#"
crt.Screen.Send "conf t" & Chr(13)
crt.Screen.WaitForString "(config)#"
crt.Screen.Send "br" & Chr(13)
crt.Screen.WaitForString "#"

CARD=inputbox("Please Enter Dslam Card", "Dslam Card")
    If Card="" Then
        MsgBox"Operation Cancelled"
        crt.Screen.Send "end" & Chr(13)
        crt.sleep 500
        crt.Screen.Send "exit" & Chr(13)
        ThisIsTheEnd
    End If
    
PORT=inputbox("Please Enter Dslam Port", "Dslam Port")
    If Port="" Then
        MsgBox"Operation Cancelled"
        crt.Screen.Send "end" & Chr(13)
        crt.sleep 500
        crt.Screen.Send "exit" & Chr(13)
        ThisIsTheEnd
    End If  

Sub Main() 

Profile

NextAction

ThisIsTheEnd

End Sub

Sub Profile

SELPROFILE=inputbox("1.free_VDSL_8B_Default" & Chr(13) & "2.free_VDSL_12A" & Chr(13) & "3.free_VDSL_17A", "Please Select the Profile")
crt.Screen.Send "port lre" & " " & CARD & "/" & PORT & " disable" & Chr(13)
crt.sleep 500

    If SELPROFILE=1 Then
            MsgBox "Default 8B Profile Selected"
        crt.Screen.Send "lre" & " " & CARD & "/" & PORT & " xdsl line-config free_VDSL_8B_Default" & Chr(13) 
        ElseIf SELPROFILE=2 Then
        MsgBox "12A Profile Selected"
        crt.Screen.Send "lre" & " " & CARD & "/" & PORT & " xdsl line-config free_VDSL_12A" & Chr(13) 
    ElseIf SELPROFILE=3 Then 
        MsgBox "17A Profile Selected"
        crt.Screen.Send "lre" & " " & CARD & "/" & PORT & " xdsl line-config free_VDSL_17A" & Chr(13)
    ElseIf SELPROFILE<>1 or 2 or 3 Then
        MsgBox "INVALID PROFILE!!!", 0+16+0+4096
        Profile
    End If 
    
crt.sleep 500
crt.Screen.Send "port lre" & " " & CARD & "/" & PORT & " enable" & Chr(13)
crt.sleep 500
crt.Screen.Send "end" & Chr(13)
crt.sleep 500
crt.Screen.Send "wr mem" & Chr(13)
crt.Screen.WaitForString "#"

End Sub 

Sub NextAction

GOON=inputbox("1.Exit" & Chr(13) & "2.Show Sync" & Chr(13) & "3.Repeat", "Please select next action")
    if GOON=1 then 
        crt.Screen.Send "exit" & Chr(13)
    ElseIf GOON=2 then 
        crt.Screen.Send "sho lre" & " " & CARD & "/" & PORT & " xdsl phys-table linerates" & Chr(13)
        NextAction
    ElseIf GOON=3 then
        crt.Screen.Send "conf t" & Chr(13)
        crt.Screen.WaitForString "(config)#"
        crt.Screen.Send "br" & Chr(13)
        crt.Screen.WaitForString "#"    
        Profile
    Else    MsgBox "INVALID SELECTION!!!", 0+16+0+4096
        NextAction  
    End if

End Sub

Sub ThisIsTheEnd

    MsgBox"Thank you, come again"
    crt.Quit

End Sub

So to summarize everything up, I want to have the option of exiting the script at the various message-input boxes stages, via the cancel option and without closing Secure CRT.

The whole script has to run through Secure CRT so the WScript.Quit is not an option.

Thank you for your time!


Solution

  • So the problem was finally solved by a declaring globally the variables used on the subs, adding a Do Until Loop and rearranging the subs in order that the script can end with the Exit and End Sub commands.

    Looks like the End Sub (when used correctly) is enough for terminating the script at any point desired.