Welcome Guest.   Make a donation to an author on the site November 24, 2014, 12:51:43 AM  *

Please login or register.
Or did you miss your validation email?


Login with username and password (forgot your password?)
Why not become a lifetime supporting member of the site with a one-time donation of any amount? Your donation entitles you to a ton of additional benefits, including access to exclusive discounts and downloads, the ability to enter monthly free software drawings, and a single non-expiring license key for all of our programs.


You must sign up here before you can post and access some areas of the site. Registration is totally free and confidential.
 
The N.A.N.Y. Challenge 2010! Download 24 custom programs!
   
   Forum Home   Thread Marks Chat! Downloads Search Login Register  
Pages: [1]   Go Down
  Reply  |  New Topic  |  Print  
Author Topic: autohotkey arrays  (Read 8509 times)
justice
Supporting Member
**
Posts: 1,889



Solve issues simply.

View Profile WWW Give some DonationCredits to this forum member
« on: September 17, 2008, 07:45:36 AM »

I'm always fighting with them can you tell me what's the easiest way to maintain a list of strings, add a listitem, remove a listitem, return a listitem? For example I'd like to keep a list of hidden window titles and then unhide one and remove it from the list. Autohotkey makes it really hard, I usually build a concatenated string and split them into an array but then when i want to return a value but am not sure where its position is it's near impossible.

Any ideas?
Logged

jgpaiva
Global Moderator
*****
Posts: 4,711



Artificial Idiocy

see users location on a map View Profile WWW Read user's biography. Give some DonationCredits to this forum member
« Reply #1 on: September 17, 2008, 11:56:14 AM »

I agree, it's a pain in the *** to use ahk's arrays..
Here's how I usually do it:
[copy or print]
loop,%loopIter%
{
   TempVar := ArrayVar%A_Index%        ;store ArrayVar[i] in temp variable
   msgbox,TempVar                      ;use temp variable
   ArrayVar%A_Index% := A_Index * 4    ;store value in ArrayVar[i]
}
Logged

justice
Supporting Member
**
Posts: 1,889



Solve issues simply.

View Profile WWW Give some DonationCredits to this forum member
« Reply #2 on: September 17, 2008, 12:00:48 PM »

So with your example if I want to remove one item i have to look through the whole array and check a condition, breaking the loop if condition is true. Hm
Logged

jgpaiva
Global Moderator
*****
Posts: 4,711



Artificial Idiocy

see users location on a map View Profile WWW Read user's biography. Give some DonationCredits to this forum member
« Reply #3 on: September 17, 2008, 12:20:52 PM »

justice: notice that in terms of removing, ahk's arrays are pretty much like any other arrays: there's no way to do so smiley
What you can do it loop through the whole array, get the element you want, and then move all the elements that follow that one to the previous position.
If you're intentions are to add and remove elements (which are not the last element of the array), you're probably better off with a comma-separated list.
Logged

Target
Honorary Member
**
Posts: 1,411



see users location on a map View Profile WWW Give some DonationCredits to this forum member
« Reply #4 on: September 17, 2008, 07:14:03 PM »

not sure if this is exactly what you want, (or even if it does what you want  embarassed) but there's a minimize to tray script in the help file that i think does this - search on tray

I've been using this script for some time though I've not studied the code  embarassed embarassed   
Logged

"Look wise, say nothing, and grunt. Speech was given to conceal thought" - Sir William Osler
rulfzid
Participant
*
Posts: 28



View Profile Give some DonationCredits to this forum member
« Reply #5 on: December 12, 2008, 12:31:36 AM »

I'm always fighting with them can you tell me what's the easiest way to maintain a list of strings, add a listitem, remove a listitem, return a listitem? For example I'd like to keep a list of hidden window titles and then unhide one and remove it from the list. Autohotkey makes it really hard, I usually build a concatenated string and split them into an array but then when i want to return a value but am not sure where its position is it's near impossible.

Any ideas?

I know this thread is a bit old, but here are a couple of threads you could take a look at from the AHK forums:

SimpleArray
AHKArray

Also, for your initial problem, I'd first recommend working with window handles instead of window titles, but either way, you could use the native AHK string commands, which are pretty fast:

[copy or print]
hiddenwindowlist = window 1,window 2,window 3,window 4,

MsgBox, % "The current list: " hiddenwindowlist

unhide( "window 3", hiddenwindowlist)

MsgBox, % "The new list: " hiddenwindowlist

unhide( wintitle_to_unhide, ByRef wlist )
{
    If wintitle_to_unhide in %wlist%                            ; is wintitle_to_unhide in our list?
    {
        MsgBox, % "Unhiding " wintitle_to_unhide                ; then show the window
        StringReplace, wlist, wlist, %wintitle_to_unhide%`,     ; and remove it from the list
    }
}

Logged
justice
Supporting Member
**
Posts: 1,889



Solve issues simply.

View Profile WWW Give some DonationCredits to this forum member
« Reply #6 on: December 12, 2008, 03:44:41 AM »

Thanks so much for your  post rulfzid! AHKArray looks promising and I learned a lot from your example. I always used Instring to check if a value was in a string but the if statement you used is more readable, and the string replace is clever.
Logged

Pages: [1]   Go Up
  Reply  |  New Topic  |  Print  
 
Jump to:  
   Forum Home   Thread Marks Chat! Downloads Search Login Register  

DonationCoder.com | About Us
DonationCoder.com Forum | Powered by SMF
[ Page time: 0.031s | Server load: 0.03 ]