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 

combining variables

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



Joined: 13 May 2008
Posts: 7

PostPosted: Mon Jun 02, 2008 4:20 pm    Post subject: combining variables Reply with quote

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
View user's profile Send private message
Guest1
Guest





PostPosted: Mon Jun 02, 2008 4:42 pm    Post subject: Reply with quote

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

PostPosted: Mon Jun 02, 2008 7:06 pm    Post subject: Reply with quote

There is also .= operator

Code:
var1 := "AutoHotkey "
var2 := "Scripting "
var3 := "Language"

var .= var1 .= var2 .= var3

MsgBox, % var


Smile
Back to top
View user's profile Send private message
engunneer



Joined: 30 Aug 2005
Posts: 6847
Location: Pacific Northwest, US

PostPosted: Mon Jun 02, 2008 8:36 pm    Post subject: Reply with quote

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



Joined: 26 Dec 2005
Posts: 6264

PostPosted: Mon Jun 02, 2008 8:43 pm    Post subject: Reply with quote

Hi engunneer Very Happy

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! Embarassed
Back to top
View user's profile Send private message
engunneer



Joined: 30 Aug 2005
Posts: 6847
Location: Pacific Northwest, US

PostPosted: Mon Jun 02, 2008 8:45 pm    Post subject: Reply with quote

Hey SKAN Cool,

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



Joined: 17 Oct 2006
Posts: 2737
Location: Australia, Qld

PostPosted: Mon Jun 02, 2008 8:51 pm    Post subject: Reply with quote

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



Joined: 26 Dec 2005
Posts: 6264

PostPosted: Mon Jun 02, 2008 8:52 pm    Post subject: Reply with quote

engunneer wrote:
but what remains in var1, etc. after your creative syntax?


left-to-right evaluation..mmm.
should contain concatenated values .. Shocked I did not think of that, but might produce desirable results in certain situations ( which I am not able to guess right now )

Very Happy
Back to top
View user's profile Send private message
engunneer



Joined: 30 Aug 2005
Posts: 6847
Location: Pacific Northwest, US

PostPosted: Mon Jun 02, 2008 8:59 pm    Post subject: Reply with quote

SKAN wrote:
Shocked 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.)

Surprised
_________________
Unless otherwise noted, all code is untested.
Common Answers: 1.(Loops, Viruses, etc.) 2. Search 3.RTFM
Back to top
View user's profile Send private message Visit poster's website
SKAN



Joined: 26 Dec 2005
Posts: 6264

PostPosted: Tue Jun 03, 2008 9:25 am    Post subject: Re: combining variables Reply with quote

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


Smile
Back to top
View user's profile Send private message
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