Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have been making alot of random scripts lately, none of which are really useful for anything but they help me to understand various things and I use them for reference quite often... anyways, one of the outline button options for one of my scripts is a popup msgbox generator that generates a code that I can just copy and paste (there are alot of message boxes in the script)
but I am having trouble with the variable being displayed in the input '$codebox':

$code = "MsgBox(0, $title, $message)"  
GUICtrlSetData($codebox, $code)

this displays:

"MsgBox(0, $title, $message)"   

rather than the data stored inside the variable.

Can I contain a variable inside a variable like this? I am not really sure how else to so this.. Does anybody have a possible workaround I could take a look at? I have searched around but I came up empty.

ps: the updated script can be found here

share|improve this question
1  
Tried without the " " around the MsgBox ? (sorry I haven't tested it just a quick glance over the code) I believe the " " makes $code think it is just a string rather than a code. –  Darius Oct 6 '13 at 3:22
    
Nice, this got past the error, but doing this brings the message box up and returns a 1 to the codebox.. ? –  ICE Oct 6 '13 at 3:30
1  
I'm still learning about AutoIT script as well, but I do notice MsgBox returns a value after a successful / failed run, hence why the return code autoitscript.com/autoit3/docs/functions/MsgBox.htm –  Darius Oct 6 '13 at 7:58
add comment

1 Answer 1

up vote 2 down vote accepted

Possible solution: $code = MsgBox (0,$title,$message)

But this will trigger and show the MessageBox at that point (not at GUICtrlSetData).

When you click on "ok" on the MsgBox, it returns the value of your action as per this link: http://www.autoitscript.com/autoit3/docs/functions/MsgBox.htm

Hence why $code returns 1 - which indicates that you clicked OK.

EDIT: (Now that I understand what ICE wanted to get) Use this code:

$code = 'MsgBox(0, ' & '"' & $title & '"' & ', ' & '"' & $message & '"' & ')'

Ok before you (and other) shoot me with WTF and all the " and ' usage, let me explain:

When you printed $code, it will generate:

MsgBox(0, "test", "messages and messages and messages")

Those code, as ICE would like it, is something that can be copied, and used straight away into ICE's code. Hence why the need to use single quote (') to lock in the text, and putting double quotes (") as a normal text - to generate the above code.

If I didn't put combination of single and double quotes, it will generate (something that I found out after testing):

MsgBox(0, test, messages and messages and messages)

And that code above will not work after simple copy and paste into AutoIt. You need to add those quotes (either double, or single).

AutoIT works with either single, or double quotes as the text marker, so stick with one that you are comfortable with. When you need to escape a double quote as text, use single quote as your text-marker, and vice versa.

Hope this helps.

share|improve this answer
    
Thanks for the help, Darius. I am trying to get the status bar to show the command for MsgBox, with the given title & message included in the codebox, Or possibly include a button function to place the MsgBox command into the script so I don't actually have to type the MsgBox command. My end goal is to build a type of script builder, or possibly even a text editor.. I am working on one piece at a time, though –  ICE Oct 6 '13 at 11:56
    
@ICE Sorry if I misunderstood your intention.. if you want that "status bar" to show the command for the MsgBox, then your current code ($code = "MsgBox....." is correct as it shows exactly what will show up - but since you have the "" then the MsgBox is not shown as it is being treated as text. If you want both the MsgBox to appear, and the code to appear, you may need a $code2 without "" and $code1 with "" to keep the text of the code. Or am I misunderstanding something? –  Darius Oct 6 '13 at 12:00
    
I would like the full msgbox command to be displayed in the codebox, without (if possible) actually bringing the message box up.. What exactly do you mean by $code2? Should I be trying to re-trap the command in another variable? When I remove the quotation marks, it returns the 1 instead of the command. Can I do this with avoiding the message box actually popping up? Sorry if that was not clear, my mind is kind of all over the place right now :P –  ICE Oct 6 '13 at 12:08
    
Nice, the edit did exactly what I was looking for. I usually have trouble with the quote marks, now I understand why. Thank you again, Darius, you have been a big help! –  ICE Oct 6 '13 at 12:36
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.