AutoHotkey Community

It is currently May 26th, 2012, 11:14 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 97 posts ]  Go to page Previous  1, 2, 3, 4, 5, 6, 7  Next
Author Message
 Post subject:
PostPosted: June 22nd, 2008, 6:58 pm 
Offline

Joined: March 19th, 2007, 12:43 am
Posts: 532
I see no examples of multidimensional arrays in your first post.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 22nd, 2008, 10:37 pm 
Offline

Joined: December 13th, 2006, 7:16 am
Posts: 48
Look again. It's under "Code Sample".
(Note: it uses non-HEXed AHKArrays)

Here's a sample for HEXed AHKArrays:
Code:
MyArray := AHKANewArray()
MyArray := AHKAAdd(MyArray,"A")
MyArray := AHKAAdd(MyArray,"B")
MySubArray := AHKANewArray()
MySubArray := AHKAAdd(MySubArray,"C1")
MySubArray := AHKAAdd(MySubArray,"C2")
MyArray := AHKAAdd(MyArray,MySubArray)
MyArray := AHKAAdd(MyArray,"D")
; MyArray will be [A,B,[C1,C2],D]


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 30th, 2008, 11:51 pm 
Offline

Joined: December 13th, 2006, 7:16 am
Posts: 48
Version 6 is done. Thanks for waiting!


Report this post
Top
 Profile  
Reply with quote  
 Post subject: CSV Array
PostPosted: September 8th, 2008, 9:17 pm 
Offline

Joined: July 19th, 2008, 3:28 am
Posts: 1
Location: Greenville
I have been using AHK since march, but this is the first time I have asked for help (I read the forum A LOT). I am trying to load a CSV file into an array to pull back information about companies I work with. The CSV file is like this:

CompanyID#,CompanyName,CompanyType. So far, I have been able to add the first field into the array, but I can't seem to pull back the data about the company. I will be using the CompanyID# to look up data.
Code:

myArray := AHKA_NewArray()


CsvSource = c:\SvcrList.csv


Loop Read, %CsvSource%
{
   Loop Parse, A_LoopReadLine, CSV
   {
      If (A_Index = 1)
      {
         ArrayName = %A_LoopField%
         %ArrayName% := AHKA_NewArray()
      }
      If (A_Index > 1)
         %ArrayName% := AHKA_Add(%ArrayName%, "%A_LoopField%")
   }
myArray := AHKA_Add(myArray, ArrayName)
}


This would be a great function to add to AHKA...
AHKA_CSVread
AHKA_CSVwrite


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 8th, 2008, 10:56 pm 
Offline

Joined: December 13th, 2006, 7:16 am
Posts: 48
To look up the data using CompanyID#, I suggest using a different system to store the data, since AHKA can only get data by indexes.
Something like:
Code:
CsvSource = c:\SvcrList.csv
ArrayName := ""
Loop Read, %CsvSource%
{
   Loop Parse, A_LoopReadLine, CSV
   {
      If (A_Index = 1)
      {
         ArrayName := A_LoopField
         Company%ArrayName% := AHKA_NewArray()
      }
      If (A_Index > 1)
      {
         Company%ArrayName% := AHKA_Add(Company%ArrayName%, A_LoopField)
      }
   }
}

; Now, to look up the CompanyType of the company which has CompanyID# of "57" (for example)
CompanyType := AHKA_Get(Company57, 3)

Hope that helped, feel free to ask more if you need help =)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 8th, 2008, 10:23 pm 
Offline

Joined: November 24th, 2007, 9:07 pm
Posts: 774
I've noticed in the documentation under Find all of the examples use the AHKA_Search syntax.

You may want to standardize the documentation there to use the correct value, since the other titles all match up to the function syntax.

No big deal however :)

Thanks for the awesome array functions that have made SteamLab's code much simpler!

Theoretical question for you:

I'm a PHP programmer and am used to using arrays with named keys. The closest I've come to this system is by creating a nested array under each array with two values, the title, and the contents. In this way, I can store and retreive information based on the array "key" value for infinitely nested arrays.

Unfortunately, I have no system in place to make sure that the keys are unique, and it is a little cumbersome locating the correct key by searching and getting the array's index and then getting the value (index 2 of the sub-array). This obviously isn't a very good system, but the only way I found to keep good organization with sub-arrays.

Do you think implementing an Key => Value array system in AHK would be feasible? Maybe another project for me to tackle at some point.

_________________
Ben

My Trac projects
My Wiki
[Broken] - My music


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 9th, 2008, 2:49 am 
Offline

Joined: December 13th, 2006, 7:16 am
Posts: 48
Cool! Thank you for pointing that out! I'll get that fixed at the same time as I finish up all the tutorials (on some break - like christmas).

I took a look at SteamLab, looks like a cool project! Keep up the good work. =D

For key arrays, it would definetly be cumbersome, but it can be done. I myself am somewhat used to PHP style arrays, but luckily program in so many langs that it's not really a problem. For single dimensional arrays it could even be done rather simply by keeping a delimitered list of pairs of values, some like
Code:
arr = a:59,big:23,realvalue=1
By keeping it alphabetized it would make it simple to not allow a user to add duplicate key values.

However, a better or rather simpler system would be to make something like an addon to AHKA (or SimpleArray) which would consist of an array which has two values on every field, like:
Code:
key1:1,zed:51
where the second value would point to a place in an AHKArray. That way multidimensionality could easily be preserved, and all the functions of AHKA could still easily be used, or rather ported. Say for example function KeyArray_Remove() would just need to call AHKA_Remove(). Or well, functions like add/remove/insert would also need to update the key array itself... but, well, you get my point right?
That would be interesting to look into, and if I ever have enough time to do something like this, I just might. =)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 9th, 2008, 3:51 am 
Offline

Joined: November 24th, 2007, 9:07 pm
Posts: 774
That is an interesting idea. Could you explain in a little more detail the purpose of the number that points to a place in an AHKA array?

Are you saying it would require two arrays, an array of keys and pointers, and an array of actual data? Or am I reading that wrong?

The way I first though about it, though this might be flawed, is to create wrapper functions for AHKA. Each time you write a value to an array with the wrapper function, it would write the value to AHKA as
Code:
[Key,Value]
(eg a new array). Another function would need to be made to properly look something up by key, which would probably require a search? That's why I think that's flawed, and why I should try to understand your idea better :)

_________________
Ben

My Trac projects
My Wiki
[Broken] - My music


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 9th, 2008, 5:56 pm 
Offline

Joined: December 13th, 2006, 7:16 am
Posts: 48
Mmm, the wrapper idea is correct, but, it writing a sub-array is bad, because it will screw a lot of dimensionality up, and will need to be rather complex.

I was thinking along the lines of having the first slot in an array hidden (so like arr[0] <- which wouldn't be a problem since array starts at 1, and functions could be changed to SimpleArray style where -1 = last element). This first slot would store one array that would look something like this:
Code:
[key1:index1,key2:index2,key3:index3]
so the entire AHKA Key Array would look like
Code:
[[aardvark:1,potato:3,zeebra:2],"is a bird","is a horse","is a vegetable"]

Hope that explains it a bit more clearly.

The reason for having this array at all is to keep it always alphabetized as to not allow duplicate keys.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 9th, 2008, 6:33 pm 
Offline

Joined: November 24th, 2007, 9:07 pm
Posts: 774
Ah, yes; that makes a lot more sense to me now.

Maybe as an alternative then to accessing nested PHP arrays like $array['key']['key']['key']
something could be done like
Key_Array(Array, "key/key/key")

Though there may even be a better way to do that.

I won't worry about any of this for now, as I can get by with what's available for now, but I may try and tackle this at some point if it hasn't already been :)

Thanks for the info.

_________________
Ben

My Trac projects
My Wiki
[Broken] - My music


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 9th, 2008, 6:44 pm 
Offline

Joined: December 13th, 2006, 7:16 am
Posts: 48
Actually, this works out for multi-dimensional arrays all by itself, take a look at this:
Code:
arr = [[key1:1,key2:2,key3:3],one,[[key21:1,key22:2,key23:3],twosub1,twosub2,twosub3],three]

This would be an equivalent of this in PHP:
Code:
Arr = {
Key1=>one
Key2=>{
Key21=>twosub1
Key22=>twosub2
Key23=>twosub3
}
Key3=>three
}

(Hopefully my PHP isn't so rusty that the above is syntaxed wrong XD)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 10th, 2008, 3:53 pm 
Offline

Joined: November 24th, 2007, 9:07 pm
Posts: 774
No, you're right about creating multi-dimensional arrays, I was referring to accessing them however. In PHP you can just chain the array path together with the variable name like:

Code:
$value = $arr['key1']['key21']


I think with AHKArray you would need to start at the first level, get the value (to convert the hex back), then get the subarray from that level, etc. Or is there a way to access a deeper value in an array such as that already?

_________________
Ben

My Trac projects
My Wiki
[Broken] - My music


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 10th, 2008, 6:04 pm 
Offline

Joined: December 13th, 2006, 7:16 am
Posts: 48
Ah, I see, no, that's already built in with function overloading.
You'd just call AHKA_Get(arr,key2,key23) to get value at array=>key2=>subarray=>key23=>value. Well, the Get function would have to change to accept keys, but it would be something like AHKA_KGet(arr,key2,key23).


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 10th, 2008, 8:45 pm 
Offline

Joined: November 24th, 2007, 9:07 pm
Posts: 774
Oh yeah; cool! It doesn't sound like implementing a named key system (or wrapper for AHKA/SA) would be overly difficult. Thanks for all the info provided! :)

_________________
Ben

My Trac projects
My Wiki
[Broken] - My music


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 31st, 2008, 3:09 pm 
Offline

Joined: March 2nd, 2007, 7:25 am
Posts: 57
Location: Germany
Hi!
I want to store the content of the clipboardAll variable in an array. I can't get it to work. Is there a way to do it? Would this be possible with SimpleArray?

Thank you!


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 97 posts ]  Go to page Previous  1, 2, 3, 4, 5, 6, 7  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: Exabot [Bot] and 11 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group