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 

variables

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Wish List
View previous topic :: View next topic  
Author Message
Jon



Joined: 28 Apr 2004
Posts: 373

PostPosted: Thu May 27, 2004 12:47 pm    Post subject: variables Reply with quote

Hi, I can't finds a way that will allow me to for example print out a variaable in a loop e.g.

To print ouy the 5 times table I would do the following-

Code:

^t::

i=0
x=0

loop
{
variable%i%=%x%

i++

x+=5

if i=5
{
break
}

}

; At the moment, this would need to be printed out like this

send, %variable1%`n%variable2%`n%variable3%`n%variable4%`n%variable5%



I can't see a way of printing it out in a loop like this maybe-

Code:

i=0

loop
{
send, %variable%%i%`n
i++
}


Or maybe something like this-

Code:

i=0

loop
{
send, % %variable%%i% %`n
i++
}


something like an array

Thanks, Jon
Back to top
View user's profile Send private message Send e-mail
Jon



Joined: 28 Apr 2004
Posts: 373

PostPosted: Thu May 27, 2004 12:59 pm    Post subject: Reply with quote

Sorry, Just looked up arrays in the help, I should have done that first.

Code:

; Write to the array:

x=0

loop, 5
{
   array%a_index%=%x%
x+=5
}

; Read from the array:
loop
{
   StringTrimRight, element, array%a_index%, 0
   if element =
      break ; The end of the array has been reached.
   MsgBox, %element%
}


That seems to work, Thanks, Jon
Back to top
View user's profile Send private message Send e-mail
Jon



Joined: 28 Apr 2004
Posts: 373

PostPosted: Thu May 27, 2004 9:18 pm    Post subject: Reply with quote

I have tried the solution in my last post but it seems quite hard to work with. I was wondering if it would be possible to make the arrays work more like other programming languages such as C and java or like in my first post-

Code:

loop
{
send, %variable%%i%`n
i++
}


or-

Code:

loop
{
send, That vairable is "%d" ,variable[i]
i++
}


or-

Code:

loop
{
send, That vairable is %variable[i]%
i++
}


to fill an array-

Code:

InputBox, OutputVar

array[i]=%Outputvar%
i++


or-

Code:


i=0
x=0
loop, 5
{
array[i]=%x%

i++
x+=5

}


it would make it easier to store arrays or strings as well if you could store them in memory and then access them from an array.

maybe structs and multidimentional arrays as well but that might be going too far and over complicating it. And I've never like structs.

I don't mind if these can't be implemented or are too complicated to implement. Knowing me they probably alread exist lol Very Happy

thanks, Jon
Back to top
View user's profile Send private message Send e-mail
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10464

PostPosted: Thu May 27, 2004 10:04 pm    Post subject: Reply with quote

Quote:
send, That vairable is %variable[i]%

The above syntax is something I've put a lot of thought into. I've come to the conclusion that AHK's syntax just isn't very amenable to changes like the above. In other words, the cost of a simple syntax (with no need for double quotes around strings) is that adding syntax to support complex expressions, user defined functions, and arrays is difficult.

Quote:
array[i]=%Outputvar%
i++

Code:
i=0
x=0
loop, 5
{
     array[i]=%x%
     i++
     x+=5
}

The above examples are already supported, except that you have to use percent signs instead of brackets:
array%i% = %Outputvar%
i++

In other words, anywhere the name of an input variable or output variable is expected, you can use percent signs to make that variable be resolved dynamically during the script's execution.

Quote:
maybe structs and multidimentional arrays as well but that might be going too far and over complicating it.

Although I haven't actually tried it, you should be able to do multidimensional arrays, but to avoid ambiguity between elements, you'll need a separator between dimensions:
array%i%_%j% = %MyVar%

Thanks for your suggestions, it's good to know that others are thinking along the same lines I have. Hopefully, some more improvements can be made based on the insight of you and others.
Back to top
View user's profile Send private message Send e-mail
Jon



Joined: 28 Apr 2004
Posts: 373

PostPosted: Fri May 28, 2004 2:07 pm    Post subject: Reply with quote

Quote:

The above examples are already supported, except that you have to use percent signs instead of brackets:
array%i% = %Outputvar%
i++


Sorry, I forgot it already did that. It seems to be easy to fill an array but difficult to print it out.

Quote:

Although I haven't actually tried it, you should be able to do multidimensional arrays, but to avoid ambiguity between elements, you'll need a separator between dimensions:
array%i%_%j% = %MyVar%


thanks, I will give that a try.

It would be good if eventually autohotkey could do something like that eventually but like with most things, there is normally already a work around with autohotkey.

Thanks for taking the time to go over this for me.

Thanks, Jon
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Wish List 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