 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
Jon
Joined: 28 Apr 2004 Posts: 373
|
Posted: Thu May 27, 2004 12:47 pm Post subject: variables |
|
|
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 |
|
 |
Jon
Joined: 28 Apr 2004 Posts: 373
|
Posted: Thu May 27, 2004 12:59 pm Post subject: |
|
|
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 |
|
 |
Jon
Joined: 28 Apr 2004 Posts: 373
|
Posted: Thu May 27, 2004 9:18 pm Post subject: |
|
|
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
thanks, Jon |
|
| Back to top |
|
 |
Chris Site Admin
Joined: 02 Mar 2004 Posts: 10464
|
Posted: Thu May 27, 2004 10:04 pm Post subject: |
|
|
| 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 |
|
 |
Jon
Joined: 28 Apr 2004 Posts: 373
|
Posted: Fri May 28, 2004 2:07 pm Post subject: |
|
|
| 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 |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|