VanDyke Software Forums

VanDyke Software Forums (https://forums.vandyke.com/index.php)
-   Scripting (https://forums.vandyke.com/forumdisplay.php?f=14)
-   -   Python handle crt.Dialog.Prompt handling (https://forums.vandyke.com/showthread.php?t=13532)

christopherchiu 05-07-2019 10:18 PM

Python handle crt.Dialog.Prompt handling
 
In SecureCRT, i have a script that display 2 dialog boxes for inputs. i want to exit out when either (a) user hit <cancel>, or (b) user hit <ok> but nothing was entered.

When in VB, there is a system variable Err.Number. How is it in python? Thanks

bgagnon 05-08-2019 08:27 AM

Hi christopherchiu,
Quote:

In SecureCRT, i have a script that display 2 dialog boxes for inputs. i want to exit out when either (a) user hit <cancel>, or (b) user hit <ok> but nothing was entered.
There's an example in the SecureCRT Help topic for Dialog Object / Prompt Method (Scripting / Script Objects Reference):

Quote:

Python
Syntax
crt.Dialog.Prompt(message [, title [, default [, isPassword ]]])
Example
password = crt.Dialog.Prompt("Enter your password:", "Logon Script", "", True)
if password == "":
# User clicked Cancel button
else:
# User added data

The if == "" would cover both a cancel or empty scenario. To exit out, use return or break.

Quote:

When in VB, there is a system variable Err.Number. How is it in python? Thanks
As I told you in email, I don't know that there is a direct equivalent. If you wrap code in a try/except block there are built-in exceptions available in Python but that's more a Python inquiry than it is SecureCRT. :)


All times are GMT -6. The time now is 05:42 AM.