VanDyke Software Forums

VanDyke Software Forums (https://forums.vandyke.com/index.php)
-   Scripting (https://forums.vandyke.com/forumdisplay.php?f=14)
-   -   Cancel script without prompt (https://forums.vandyke.com/showthread.php?t=11716)

e2script 09-29-2014 04:38 AM

Cancel script without prompt
 
Hi.

I'm currently building a script where I want the script to be cancelled when one of the if statements is met.

See the example below:
Code:

result0 = crt.Screen.WaitForStrings("x","y")

if result0 = 1 Then
crt.screen.Send "hello"
end if

if result0 = 2 Then
crt.screen.SendSpecial "MENU_SCRIPT_CANCEL"

This works fine and the script is doing what it's supposed to.
The only problem is that when the script is cancelled a dialogbox is presented saying that the script was cancelled.
The only way to remove the dialogbox is to click the OK button.

Is there any way to cancel the script without receiving the dialogbox?

rtb 09-29-2014 09:37 AM

It is possible to accomplish your goal using VBScript error handling.

Here is an example:
Code:

On Error Resume Next
If result0 = 2 Then
    crt.screen.SendSpecial "MENU_SCRIPT_CANCEL"
End If
On Error Goto 0


e2script 09-30-2014 02:18 AM

I can't seem to get that command to work properly.

Here's the first part of my script where the canceling of the script might be necessary.

Code:

crt.Screen.Synchronous = True

'This part dnstelnet's the hostname or ip-address you have copied to your clipboard. #######

crt.screen.Send "telnet "
crt.screen.SendSpecial "MENU_PASTE"
crt.screen.Send "" & vbCr

result0 = crt.Screen.WaitForStrings("Name or service not known","Connected to")
'Name or service not known = when it doesn't work to telnet the host.
'Connected to = when it works to telnet the host.

'If it doesn't work to telnet the host try to dnstelnet the host.
if result0 = 1 Then
crt.screen.Send "dnstelnet "
crt.screen.SendSpecial "MENU_PASTE"
crt.screen.Send "" & vbCr

result3 = crt.Screen.WaitForStrings("has address","$","Connected to")

'If it doesn't work to dnstelnet the host because there's severeal hosts matching the criteria then cancel the script.
On Error Resume Next
if result3 = 1 Then
crt.screen.SendSpecial "MENU_SCRIPT_CANCEL"
end if
On Error Goto 0

'If it doesn't work to dnstelnet the host because there's no hosts matching the criteria then cancel the script.
On Error Resume Next
if result3 = 2 Then
crt.screen.SendSpecial "MENU_SCRIPT_CANCEL"
end if
On Error Goto 0

'If it works to dnstelnet the host then continue with the login.
if result3 = 3 Then
end if
end if


'If it works to telnet the host then continue with the login.
if result0 = 2 Then
end if

I don't know if I'm doing it right or if I misunderstood your response.
The script is cancelled but I'm still receiving a dialogbox.

rtb 09-30-2014 10:26 AM

Hi e2script,

What version of SecureCRT are you using?

What is the text of the dialog box you are seeing when the script is cancelled?

e2script 10-02-2014 04:43 AM

1 Attachment(s)
I'm using SeucreCRT version 6.6.3 and I have attached the message I receive.

rtb 10-03-2014 05:06 PM

Hi e2script,

Thanks for the update. I am not sure why I got a false positive in my testing when I posted a potential solution.

I get the same behavior you get.

The alternative would be to put your code in some sort of structure like a Sub or a Function, and if you get the results you don't want, exit. For example:
Code:

Sub Main
    crt.Screen.Synchronous = True
    crt.Screen.Send vbcr
    nResult = crt.Screen.WaitForStrings("x", "y")

    If nResult = 1 Then
        MsgBox "Hello World!"
    End If

    If nResult = 2 Then
        Exit Sub
    End If
End Sub

How does this work for you?


All times are GMT -6. The time now is 01:07 AM.