AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Variable mixup...

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
Titan



Joined: 11 Aug 2004
Posts: 5019
Location: imaginationland

PostPosted: Mon Aug 16, 2004 1:39 am    Post subject: Variable mixup... Reply with quote

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
View user's profile Send private message Visit poster's website
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10467

PostPosted: Mon Aug 16, 2004 1:49 am    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail
Titan



Joined: 11 Aug 2004
Posts: 5019
Location: imaginationland

PostPosted: Mon Aug 16, 2004 10:58 am    Post subject: Thanks, worked... Reply with quote

Thankyou very much. I spend countless hours trying to fix my original script and all that was stopping me was those % signs and gaps Embarassed lol.
Back to top
View user's profile Send private message Visit poster's website
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10467

PostPosted: Mon Aug 16, 2004 12:05 pm    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail
Titan



Joined: 11 Aug 2004
Posts: 5019
Location: imaginationland

PostPosted: Tue Aug 17, 2004 12:40 am    Post subject: Running the variables... Reply with quote

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
View user's profile Send private message Visit poster's website
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10467

PostPosted: Tue Aug 17, 2004 2:02 am    Post subject: Reply with quote

Quote:
How can I make the variables actually run when you click any button?

I'm not entirely sure what you're asking, but here are a few pages from the help file that may help if you haven't already read them:

http://www.autohotkey.com/docs/Tutorial.htm
http://www.autohotkey.com/docs/commands/Blocks.htm
http://www.autohotkey.com/docs/commands/Else.htm
Back to top
View user's profile Send private message Send e-mail
Titan



Joined: 11 Aug 2004
Posts: 5019
Location: imaginationland

PostPosted: Fri Aug 20, 2004 1:43 am    Post subject: Reply with quote

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 Question
Back to top
View user's profile Send private message Visit poster's website
Candle



Joined: 19 Aug 2004
Posts: 334

PostPosted: Fri Aug 20, 2004 1:57 am    Post subject: Reply with quote

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
View user's profile Send private message
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10467

PostPosted: Fri Aug 20, 2004 5:05 am    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail
Titan



Joined: 11 Aug 2004
Posts: 5019
Location: imaginationland

PostPosted: Fri Aug 20, 2004 11:10 pm    Post subject: Reply with quote

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 Crying or Very sad
Back to top
View user's profile Send private message Visit poster's website
BoBo
Guest





PostPosted: Fri Aug 20, 2004 11:46 pm    Post subject: Reply with quote

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

PostPosted: Fri Aug 20, 2004 11:54 pm    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail
Titan



Joined: 11 Aug 2004
Posts: 5019
Location: imaginationland

PostPosted: Sat Aug 21, 2004 12:33 am    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10467

PostPosted: Sat Aug 21, 2004 1:39 am    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail
Titan



Joined: 11 Aug 2004
Posts: 5019
Location: imaginationland

PostPosted: Sat Aug 21, 2004 9:46 pm    Post subject: Woohoo, got it sussed! Reply with quote

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. Very Happy
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group