Jump to content
Sign in to follow this  
Imbuter2000

no halting msgbox with difficult variable body

Recommended Posts

I need to display a no halting msgbox with a variable for body.

I'm using this code, that works most of the times:

Run (@AutoItExe & ' /AutoItExecuteLine "MsgBox(0,''titletext'',''' & $bodyvariable & ''')"')

The problems happen when $bodyvariable contains for example the characters " or ' (not sure what of the two, maybe both), for reasons that you can logically understand.

The question is: how can I modify the code to overcome this problem?

Share this post


Link to post
Share on other sites

You can use StringReplace to change all quotes in escaped quotes like this:

$bodyvariable = """This"" is a 'Test'"
ConsoleWrite($bodyvariable & @CRLF) ;Text to be displayed
$bodyvariable = StringReplace($bodyvariable,"'","''") ;escaple single quotes (prevents an error )
$bodyvariable = StringReplace($bodyvariable,'"','""') ;escape double quotes (prevents the quotes dissappearing)
Run (@AutoItExe & ' /AutoIt3ExecuteLine  "MsgBox(0, ''titletext'', ''' & $bodyvariable & ''')"')

There might be a nicer way to do it though.

Share this post


Link to post
Share on other sites

You can use StringReplace to change all quotes in escaped quotes like this:

$bodyvariable = """This"" is a 'Test'"
ConsoleWrite($bodyvariable & @CRLF) ;Text to be displayed
$bodyvariable = StringReplace($bodyvariable,"'","''") ;escaple single quotes (prevents an error )
$bodyvariable = StringReplace($bodyvariable,'"','""') ;escape double quotes (prevents the quotes dissappearing)
Run (@AutoItExe & ' /AutoIt3ExecuteLine  "MsgBox(0, ''titletext'', ''' & $bodyvariable & ''')"')

There might be a nicer way to do it though.

Right, good idea! Thanks! I will try it tomorrow in office...

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...