Jump to content

Recommended Posts

Posted

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?

Posted

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.

Posted

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...

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
×
×
  • Create New...