| View previous topic :: View next topic |
| Author |
Message |
Titan
Joined: 11 Aug 2004 Posts: 5019 Location: imaginationland
|
Posted: Mon Aug 16, 2004 1:39 am Post subject: Variable mixup... |
|
|
| Code: | SetEnv, %var1%, MsgBox, hi
SetEnv, %var2%, MsgBox, bye
MsgBox, 4, One or Two, Choose a button:
IfMsgBox, YES
%var1%
else
%var2%
return |
That is an example of a bit of a code I'm using. The part I'm having problems with starts from 'IfMsgBox...', it doesn't recognise '%var1%'.
I have tried alot of things but no luck. I want it so when the right button is clicked the respective variable function should load. Please help, thankyou. |
|
| Back to top |
|
 |
Chris Site Admin
Joined: 02 Mar 2004 Posts: 10467
|
Posted: Mon Aug 16, 2004 1:49 am Post subject: |
|
|
There's no support yet for dynamic commands; in other words, the command name cannot be contained in a variable.
Also, do not use percent signs around variables on the left side of an assignment unless you want them to be dynamic vars or arrays). For example, use "SetEnv, var1, SomeString" not "SetEnv, %var1%, SomeString".
New version:
| Code: | var1 = hi
var2 = bye
MsgBox, 4, One or Two, Choose a button:
IfMsgBox, YES
MsgBox %var1%
else
MsgBox %var2%
return |
|
|
| Back to top |
|
 |
Titan
Joined: 11 Aug 2004 Posts: 5019 Location: imaginationland
|
Posted: Mon Aug 16, 2004 10:58 am Post subject: Thanks, worked... |
|
|
Thankyou very much. I spend countless hours trying to fix my original script and all that was stopping me was those % signs and gaps lol. |
|
| Back to top |
|
 |
Chris Site Admin
Joined: 02 Mar 2004 Posts: 10467
|
Posted: Mon Aug 16, 2004 12:05 pm Post subject: |
|
|
| I don't think you're the only one confused. It's on the to-do list to enhance the tutorial with a brief description of variables. |
|
| Back to top |
|
 |
Titan
Joined: 11 Aug 2004 Posts: 5019 Location: imaginationland
|
Posted: Tue Aug 17, 2004 12:40 am Post subject: Running the variables... |
|
|
| Quote: | New version: | Code: | var1 = hi
var2 = bye
MsgBox, 4, One or Two, Choose a button:
IfMsgBox, YES
MsgBox %var1%
else
MsgBox %var2%
return |
|
In your new version of the script, when you click the buttons it gives a Message Box with the variables. How can I make the variables actually run when you click any button?
Oh yea, an easier tutorial on variables would be great! |
|
| Back to top |
|
 |
Chris Site Admin
Joined: 02 Mar 2004 Posts: 10467
|
|
| Back to top |
|
 |
Titan
Joined: 11 Aug 2004 Posts: 5019 Location: imaginationland
|
Posted: Fri Aug 20, 2004 1:43 am Post subject: |
|
|
| Code: | var1 = hi
var2 = bye
MsgBox, 4, One or Two, Choose a button:
IfMsgBox, YES
MsgBox %var1%
else
MsgBox %var2%
return |
I mean that in this script, if they click the option 'One' then how can I make it run the var1 variable  |
|
| Back to top |
|
 |
Candle
Joined: 19 Aug 2004 Posts: 334
|
Posted: Fri Aug 20, 2004 1:57 am Post subject: |
|
|
| Well if I click the Yes button it says Hi and if I click the No button ut says bye . is that not what you want ? |
|
| Back to top |
|
 |
Chris Site Admin
Joined: 02 Mar 2004 Posts: 10467
|
Posted: Fri Aug 20, 2004 5:05 am Post subject: |
|
|
It's unclear what you mean by "run the var1 variable". If you want to launch some other script, you can run it directly if it's in the same folder:
Run, Script2.ahk |
|
| Back to top |
|
 |
Titan
Joined: 11 Aug 2004 Posts: 5019 Location: imaginationland
|
Posted: Fri Aug 20, 2004 11:10 pm Post subject: |
|
|
This is an example of the script I'm making:
| Code: | var1 = MsgBox, hi
var2 = MsgBox, bye
MsgBox, 4, One or Two, Choose a button:
IfMsgBox, YES
%var1%
else
%var2%
return |
When I run the script I get the error message:
| Quote: | Error at line 5.
Line Text: %var1%
Error: This line does not contain a recognised action.
The program will exit.
[OK] |
I want the script to carry out var1 when they click 'One' (so when they click 'One' it will give a message box saying 'hi'). I know I can make it run another script in another filder but I don't want to do that. Please look at my code and try to see what the problem is... it's really fustrating me  |
|
| Back to top |
|
 |
BoBo Guest
|
Posted: Fri Aug 20, 2004 11:46 pm Post subject: |
|
|
| Quote: | | There's no support yet for dynamic commands; in other words, the command name cannot be contained in a variable. |
Means that is illegal !
| Quote: | var1 = MsgBox, hi
var2 = MsgBox, bye |
Any reason why you came back using the corrupt code ?
While this one is working fine (!) ...
| Quote: | var1 = hi
var2 = bye
MsgBox, 4, One or Two, Choose a button:
IfMsgBox, YES
MsgBox %var1%
else
MsgBox %var2% |
|
|
| Back to top |
|
 |
Chris Site Admin
Joined: 02 Mar 2004 Posts: 10467
|
Posted: Fri Aug 20, 2004 11:54 pm Post subject: |
|
|
Right, AutoHotkey cannot yet run commands contained inside a variable. Although this is planned, its an advanced feature and rarely needed for everyday scripting.
I'm assuming the script you posted -- since it clearly doesn't require the above -- is just an example of something more complex you want to do. So if you can describe your goal, someone here might be able to help more completely. |
|
| Back to top |
|
 |
Titan
Joined: 11 Aug 2004 Posts: 5019 Location: imaginationland
|
Posted: Sat Aug 21, 2004 12:33 am Post subject: |
|
|
Well I want something like this code:
| Code: | var1 = MsgBox, hi
var2 = MsgBox, bye
MsgBox, 4, One or Two, Choose a button:
IfMsgBox, YES
%var1%
else
%var2%
return |
A script that will give a Message box saying 'hi' when you press 'One' or the message 'bye' when you press 'Two'. Do you know some code which can do this? |
|
| Back to top |
|
 |
Chris Site Admin
Joined: 02 Mar 2004 Posts: 10467
|
Posted: Sat Aug 21, 2004 1:39 am Post subject: |
|
|
Yes, there's an example above in the very first reply to your post. Here is a simplified version:
| Code: | MsgBox, 4, One or Two, Choose a button:
IfMsgBox, YES
Msg = Hi
else
Msg = Bye
MsgBox %Msg%
return |
Note that you can customize the names of the buttons in a MsgBox by following this example. |
|
| Back to top |
|
 |
Titan
Joined: 11 Aug 2004 Posts: 5019 Location: imaginationland
|
Posted: Sat Aug 21, 2004 9:46 pm Post subject: Woohoo, got it sussed! |
|
|
Woohoo! I am really happy. In the end I figured out I could use the 'Goto, ' code instead of variables. Thanks anyway for your time.  |
|
| Back to top |
|
 |
|