Welcome to the VanDyke Software Forums

Join the discussion today!


Go Back   VanDyke Software Forums > Scripting

Notices

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 03-06-2018, 12:27 AM
bighalo bighalo is offline
Registered User
 
Join Date: Mar 2018
Posts: 4
Post 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.

Last edited by jdev; 03-06-2018 at 09:15 AM. Reason: wrap code in [code] blocks to preserve indentation
Reply With Quote
  #2  
Old 03-06-2018, 08:12 AM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 4,636
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.
__________________
Thanks,
--Brenda

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
  #3  
Old 03-06-2018, 02:15 PM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 4,636
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
Reply With Quote
  #4  
Old 03-06-2018, 10:35 PM
bighalo bighalo is offline
Registered User
 
Join Date: Mar 2018
Posts: 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.
Reply With Quote
  #5  
Old 03-07-2018, 11:18 AM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 4,636
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.
__________________
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
Reply With Quote
  #6  
Old 03-08-2018, 05:46 AM
bighalo bighalo is offline
Registered User
 
Join Date: Mar 2018
Posts: 4
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.
Reply With Quote
  #7  
Old 03-08-2018, 06:21 AM
bighalo bighalo is offline
Registered User
 
Join Date: Mar 2018
Posts: 4
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.
Reply With Quote
  #8  
Old 03-08-2018, 11:00 AM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 4,636
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.
Attached Images
File Type: png ForumPost#13037_SecureCRTHelpTopic.png (122.0 KB, 1315 views)
__________________
Thanks,
--Brenda

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
Reply

Tags
vbs

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -6. The time now is 11:59 PM.