| View previous topic :: View next topic |
| Author |
Message |
jonathan2260
Joined: 13 May 2008 Posts: 7
|
Posted: Mon Jun 02, 2008 4:20 pm Post subject: combining variables |
|
|
I would like to know if there is a command that would permit to just take a variable and add it to another one.
Thank You |
|
| Back to top |
|
 |
Guest1 Guest
|
Posted: Mon Jun 02, 2008 4:42 pm Post subject: |
|
|
| Code: |
Var1=1
Var2=2
Var3=%Var1%%Var2%
|
That will make Var3 = 12
If you want more of a math type of thing, like actually "adding"
you want this
| Code: |
Var1=1
Var2=2
Var3 :=Var1+Var2
|
|
|
| Back to top |
|
 |
SKAN
Joined: 26 Dec 2005 Posts: 6264
|
Posted: Mon Jun 02, 2008 7:06 pm Post subject: |
|
|
There is also .= operator
| Code: | var1 := "AutoHotkey "
var2 := "Scripting "
var3 := "Language"
var .= var1 .= var2 .= var3
MsgBox, % var |
 |
|
| Back to top |
|
 |
engunneer
Joined: 30 Aug 2005 Posts: 6847 Location: Pacific Northwest, US
|
Posted: Mon Jun 02, 2008 8:36 pm Post subject: |
|
|
is that valid syntax? Most people would write
| Code: |
var1 := "AutoHotkey "
var2 := "Scripting "
var3 := "Language"
var := var1 . var2 . var3
MsgBox, % var
|
Though, technically you can also omit the . (This bugs one of my friends quite a bit)
| Code: |
var1 := "AutoHotkey "
var2 := "Scripting "
var3 := "Language"
var := var1 var2 var3
MsgBox, % var
|
I suppose it all depends on what you want var1, var2, and var3 to contain at the end. _________________
Unless otherwise noted, all code is untested.
Common Answers: 1.(Loops, Viruses, etc.) 2. Search 3.RTFM |
|
| Back to top |
|
 |
SKAN
Joined: 26 Dec 2005 Posts: 6264
|
Posted: Mon Jun 02, 2008 8:43 pm Post subject: |
|
|
Hi engunneer
| engunneer wrote: | | is that valid syntax? Most people would write ... |
I do not know! I simply tried and it worked! I would never use it!  |
|
| Back to top |
|
 |
engunneer
Joined: 30 Aug 2005 Posts: 6847 Location: Pacific Northwest, US
|
Posted: Mon Jun 02, 2008 8:45 pm Post subject: |
|
|
Hey SKAN ,
I cannot test at the moment, but what remains in var1, etc. after your creative syntax? _________________
Unless otherwise noted, all code is untested.
Common Answers: 1.(Loops, Viruses, etc.) 2. Search 3.RTFM |
|
| Back to top |
|
 |
Lexikos
Joined: 17 Oct 2006 Posts: 2737 Location: Australia, Qld
|
Posted: Mon Jun 02, 2008 8:51 pm Post subject: |
|
|
It is valid. It is evaluated as follows:
| Code: | | var .= (var1 .= (var2 .= var3)) |
| Code: | var2 := var2 . var3
var1 := var1 . var2
var := var . var1 |
| Quote: | var[29 of 63]: AutoHotkey Scripting Language
var1[29 of 63]: AutoHotkey Scripting Language
var2[18 of 63]: Scripting Language
var3[8 of 63]: Language
|
|
|
| Back to top |
|
 |
SKAN
Joined: 26 Dec 2005 Posts: 6264
|
Posted: Mon Jun 02, 2008 8:52 pm Post subject: |
|
|
| engunneer wrote: | | but what remains in var1, etc. after your creative syntax? |
left-to-right evaluation..mmm.
should contain concatenated values .. I did not think of that, but might produce desirable results in certain situations ( which I am not able to guess right now )
 |
|
| Back to top |
|
 |
engunneer
Joined: 30 Aug 2005 Posts: 6847 Location: Pacific Northwest, US
|
Posted: Mon Jun 02, 2008 8:59 pm Post subject: |
|
|
| SKAN wrote: | I did not think of that, but might produce desirable results in certain situations ( which I am not able to guess right now ) |
That was my intended message. I cannot think of a nice way to say this, but be assured i mean it in the nicest any funniest way possible:
teh point: you founds it! (I am really bad at LOLspeak)
Offtopic, I am waiting for someone to implement a LOLcode to AHK script (Either an interpreter (dynamic code? pipes?), or a translation engine.)
 _________________
Unless otherwise noted, all code is untested.
Common Answers: 1.(Loops, Viruses, etc.) 2. Search 3.RTFM |
|
| Back to top |
|
 |
SKAN
Joined: 26 Dec 2005 Posts: 6264
|
Posted: Tue Jun 03, 2008 9:25 am Post subject: Re: combining variables |
|
|
| jonathan2260 wrote: | | I would like to know if there is a command that would permit to just take a variable and add it to another one. |
.= can also be used, and here is a simple example:
| Code: | Loop %A_WinDir%\*.*
files .= A_LoopFileFullPath "`n"
MsgBox, % files |
 |
|
| Back to top |
|
 |
|