#1
|
|||
|
|||
![]()
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. Last edited by jdev; 03-06-2018 at 09:15 AM. Reason: wrap code in [code] blocks to preserve indentation |
#2
|
|||
|
|||
Hi bighalo,
Quote:
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.
__________________
Thanks, --Brenda VanDyke Software Technical Support support@vandyke.com (505) 332-5730 |
#3
|
|||
|
|||
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
__________________
Thanks, --Brenda VanDyke Software Technical Support support@vandyke.com (505) 332-5730 |
#4
|
|||
|
|||
#$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. |
#5
|
|||
|
|||
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:
__________________
Thanks, --Brenda VanDyke Software Technical Support support@vandyke.com (505) 332-5730 Last edited by bgagnon; 03-07-2018 at 11:30 AM. Reason: Asked for more info |
#6
|
|||
|
|||
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. |
#7
|
|||
|
|||
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. |
#8
|
|||
|
|||
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.
__________________
Thanks, --Brenda VanDyke Software Technical Support support@vandyke.com (505) 332-5730 |
![]() |
Tags |
vbs |
Thread Tools | |
Display Modes | Rate This Thread |
|
|