DonationCoder.com forum
 
Read-only archive. This is a static copy of the DonationCoder.com forum. Reading and searching work as before; logging in, posting and private messages do not.
Archive of 2026-10-21 · About this archive · Main site

Author Topic: autohotkey arrays  (Read 18,163 times)

justice

  • Solve issues simply.
  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 1,898
    • Participated in NANY Challenge Four Times
    • Cody Award
    • Coding Snacks
    • DJ Badge - DJ
autohotkey arrays
« on: September 17, 2008, 12:45 PM »
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?

jgpaiva

  • Artificial Idiocy
  • Global Moderator
  • Joined in 2006
  • *****
  • Posts: 4,727
    • Cody Award
    • Participated in NANY Challenge Once
    • Coding Snacks
    • Portugal Inhabitant
    • Linux User
Re: autohotkey arrays
« Reply #1 on: September 17, 2008, 04:56 PM »
I agree, it's a pain in the *** to use ahk's arrays..
Here's how I usually do it:
Code
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]
}

justice

  • Solve issues simply.
  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 1,898
    • Participated in NANY Challenge Four Times
    • Cody Award
    • Coding Snacks
    • DJ Badge - DJ
Re: autohotkey arrays
« Reply #2 on: September 17, 2008, 05:00 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

jgpaiva

  • Artificial Idiocy
  • Global Moderator
  • Joined in 2006
  • *****
  • Posts: 4,727
    • Cody Award
    • Participated in NANY Challenge Once
    • Coding Snacks
    • Portugal Inhabitant
    • Linux User
Re: autohotkey arrays
« Reply #3 on: September 17, 2008, 05:20 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 :)
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.

Target

  • Honorary Member
  • Joined in 2006
  • **
  • Posts: 1,840
    • Coding Snacks
Re: autohotkey arrays
« Reply #4 on: September 18, 2008, 12:14 AM »
not sure if this is exactly what you want, (or even if it does what you want  :-[) 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  :-[ :-[   
Alcohol is photoshop, bottled
Askhole - someone who ask for advice, then ignores it
"Look wise, say nothing, and grunt. Speech was given to conceal thought" - Sir William Osler

rulfzid

  • Participant
  • Joined in 2008
  • *
  • Posts: 28
    • Programming School - Deluxe Bonus Medal
Re: autohotkey arrays
« Reply #5 on: December 12, 2008, 06:31 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:

Code
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
    }
}

justice

  • Solve issues simply.
  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 1,898
    • Participated in NANY Challenge Four Times
    • Cody Award
    • Coding Snacks
    • DJ Badge - DJ
Re: autohotkey arrays
« Reply #6 on: December 12, 2008, 09:44 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.

Original address: https://www.donationcoder.com/forum/index.php?topic=14987.0