Home | Blog | Software | Reviews and Features | Forum | Help | Donate | About us
topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • September 03, 2015, 06:30:19 PM
  • Proudly celebrating 10 years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: autohotkey arrays  (Read 9374 times)

justice

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 1,896
    • View Profile
    • Donate to Member
autohotkey arrays
« 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?

jgpaiva

  • Global Moderator
  • Joined in 2006
  • *****
  • Posts: 4,727
    • View Profile
    • Read more about this member.
    • Donate to Member
Re: autohotkey arrays
« 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:
Code: [Select]
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

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 1,896
    • View Profile
    • Donate to Member
Re: autohotkey arrays
« 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

jgpaiva

  • Global Moderator
  • Joined in 2006
  • *****
  • Posts: 4,727
    • View Profile
    • Read more about this member.
    • Donate to Member
Re: autohotkey arrays
« 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 :)
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,501
    • View Profile
    • Donate to Member
Re: autohotkey arrays
« 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  :-[) 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  :-[ :-[   

rulfzid

  • Participant
  • Joined in 2008
  • *
  • Posts: 28
    • View Profile
    • Donate to Member
Re: autohotkey arrays
« 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:

Code: [Select]
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

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 1,896
    • View Profile
    • Donate to Member
Re: autohotkey arrays
« 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.