VanDyke Software Forums

VanDyke Software Forums (https://forums.vandyke.com/index.php)
-   Scripting (https://forums.vandyke.com/forumdisplay.php?f=14)
-   -   how to end or exit the running script (https://forums.vandyke.com/showthread.php?t=13037)

bighalo 03-06-2018 01:27 AM

how to end or exit the running script
 
I wrote a vbs:

Code:

sub main()
...

do
  nIndex = objTab.Screen.WaitForStrings(g_vWaitFors)
  if nIndex = 1 then
    ...
    <do something>
    exit sub
  end if
loop

end sub


I waitforString and do something only once.
I use "exit sub". But the script still running in loop.
How to end or stop the running script?
Is there any code available? Not Script/Cancel menu.

bgagnon 03-06-2018 09:12 AM

Hi bighalo,

Quote:

Is there any code available? Not Script/Cancel menu.
Are you saying Cancel from the Script menu is not available to you?

Getting into an infinite loop can be problematic. I have added this thread to a feature request in our product enhancement database to add a way to cancel a script that has an infinite loop. Should a future release of SecureCRT include this feature, notification will be posted here.

If you prefer direct email notification, send an email to support@vandyke.com and include "Feature Request - Forum Thread #13037" in the subject line or use this form from the support page of our website.

bgagnon 03-06-2018 03:15 PM

Hi bighalo,

As far as solving the problem of unexpected results ...

You've only provided a snippet of code and so I really do not have context for the issue, but isn't it conceivable nIndex might ever not be equal to 1?

If that's the case, exit sub is not going to get called (at least in that loop).

You might temporarily add MsgBox statements in the code at strategic points to try to verify the data:

Code:

sub main()
MsgBox "Entering Main()"
...

do
  nIndex = objTab.Screen.WaitForStrings(g_vWaitFors)
  MsgBox "nIndex: " & nIndex
  if nIndex = 1 then
    ...
    <do something>
    MsgBox "About to exit Main() subroutine"
    exit sub
  end if
loop

end sub


bighalo 03-06-2018 11:35 PM

#$language = "VBScript"
#$interface = "1.0"

g_vWaitFors = Array("Waiting for 1", "Waiting for 2")

'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Sub Main()
Set objTab = crt.GetScriptTab

If objTab.Session.Connected <> True then
crt.Dialog.MessageBox _
Exit Sub
end if

objTab.Screen.Synchronous = true

Do
nIndex = objTab.Screen.WaitForStrings(g_vWaitFors)
if nIndex = 1 then
crt.Window.Activate
result = crt.Dialog.MessageBox("gotcha","gotcha", ICON_STOP Or BUTTON_OK Or DEFBUTTON1 )
if result = IDNO then
exit sub
end if
end if
Loop
End Sub

This is my code. After the script is running in loop. When the screen get the "WaitForStrings". The messagebox will be shown. If I click OK then exit sub. But the script is still running. I don't want the script running again. What I can do is "Script/Cancel menu" to end the script. Is there any easy way to end running script.

bgagnon 03-07-2018 12:18 PM

Hi bighalo,

The suggestion is the same. Add MsgBox statements in the code at strategic points to verify the data is what you think it is. :)

There are a few flaws in the code you added as you are only providing one button, which does not include a NO button and a response of No is the only way the loop is exited early.

What are you (specifically) trying to accomplish?


Quote:

Is there any easy way to end running script.
Not at this time, other than the Cancel option you are using. Please refer to feature request info provided in my initial post.

bighalo 03-08-2018 06:46 AM

I find out the root cause.
I made a stupid mistake.

result = crt.Dialog.MessageBox("gotcha","gotcha", ICON_STOP Or BUTTON_OK Or DEFBUTTON1 )
if result = IDNO then
exit sub
end if

if result = IDNO then exit sub. but the messagebox only has the OK button.
so it will never exit sub....

I was feeling embarrassed.

bighalo 03-08-2018 07:21 AM

another problem.

result = crt.Dialog.MessageBox("gotcha","gotcha", ICON_STOP Or BUTTON_OK Or DEFBUTTON1 )
MsgBox "result=" & result
if result = IDOK then
MsgBox "About to exit Main() subroutine"
exit sub
end if

after click the OK button. result should be 1.

result = IDOK is not match.
result = 1 is.

if result = 1 then
exit sub
end if
then will end the script. this is what I had expected.

bgagnon 03-08-2018 12:00 PM

1 Attachment(s)
Hi bighalo,

Now you are mixing SecureCRT's MessageBox() method and VBScript's MsgBox() function. :)

You have to CONST them up if you want to use them. VBScript doesn't know about them. This is why the examples shown in the scripting help in SecureCRT show the CONST statements.

See attached from SecureCRT's Help topic Scripting / Script Objects Reference / Dialog Object.


All times are GMT -6. The time now is 01:29 PM.