Welcome to the VanDyke Software Forums

Join the discussion today!


Go Back   VanDyke Software Forums > Scripting

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 03-18-2019, 02:13 AM
slouw slouw is offline
Registered User
 
Join Date: Nov 2005
Posts: 144
crt.Dialog.MessageBox with variable in python

I have viewed multiple thread and posts trying to work out how to put up a message box displaying a variable.
I get different messages if I try and display an integer and a string.
But failures nevertheless.
What am I doing wrong?
Apologies I have a feeling it is something silly...

Quote:
# $language = "Python"
# $interface = "1.0"

# Hacked from GetTabByName.py.txt
#

txt_blah = "XXXXXX"
int_blah = 10
strTabTitle = crt.Dialog.MessageBox(
"Test message box : ",
"Test Messages box header I think",
int_blah)
Reply With Quote
  #2  
Old 03-18-2019, 02:40 AM
slouw slouw is offline
Registered User
 
Join Date: Nov 2005
Posts: 144
Got text variable going

This works.
The plus sign is necessary to concatenate the string variable.
If I use the integer variable I get an error cannot concatenate a number to a string.
That makes sense.
So what is a good way to output a number?

Quote:
# $language = "Python"
# $interface = "1.0"

# Hacked from GetTabByName.py.txt
#

txt_blah = "Test StringGGG"
int_blah = 10
strTabTitle = crt.Dialog.MessageBox(
"Test message box : " + txt_blah, "MessageBox Title")
Reply With Quote
  #3  
Old 03-18-2019, 03:14 AM
slouw slouw is offline
Registered User
 
Join Date: Nov 2005
Posts: 144
Convert int to string fior integer

Convert integer to string seems to work.


Quote:
# $language = "Python"
# $interface = "1.0"

# Hacked from GetTabByName.py.txt
#

txt_blah = "Working Text"
int_blah = 10
crt.Dialog.MessageBox("Test message box : " + str(int_blah), "MessageBox Title")
Reply With Quote
  #4  
Old 03-18-2019, 08:52 AM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 4,109
Hi slouw,

I am glad you were able to resolve the issue.

As a note, it is not SecureCRT's MessageBox() method that was complaining -- it was the Python script engine complaining because you effectively told the Python script engine to mathematically add an integer value to a string -- that's not possible.

The str() is needed in order to tell the Python script engine explicitly that you desire to concatenate two values (one a string, the other an integer) into a resulting string value; this requires that you explicitly convert the integer into a string (with the str() method) so that the + operator knows what result is desired.
__________________
Thanks,
--Brenda

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

Last edited by bgagnon; 03-18-2019 at 01:33 PM. Reason: Clarification
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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 01:52 AM.