 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
neXt
Joined: 18 Mar 2007 Posts: 505
|
Posted: Sun Jun 22, 2008 5:58 pm Post subject: |
|
|
| I see no examples of multidimensional arrays in your first post. |
|
| Back to top |
|
 |
olegbl
Joined: 13 Dec 2006 Posts: 48
|
Posted: Sun Jun 22, 2008 9:37 pm Post subject: |
|
|
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] |
|
|
| Back to top |
|
 |
olegbl
Joined: 13 Dec 2006 Posts: 48
|
Posted: Wed Jul 30, 2008 10:51 pm Post subject: |
|
|
| Version 6 is done. Thanks for waiting! |
|
| Back to top |
|
 |
Jdub695
Joined: 19 Jul 2008 Posts: 1 Location: Greenville
|
Posted: Mon Sep 08, 2008 8:17 pm Post subject: CSV Array |
|
|
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 |
|
| Back to top |
|
 |
olegbl
Joined: 13 Dec 2006 Posts: 48
|
Posted: Mon Sep 08, 2008 9:56 pm Post subject: |
|
|
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 =) |
|
| Back to top |
|
 |
bmcclure
Joined: 24 Nov 2007 Posts: 774
|
Posted: Wed Oct 08, 2008 9:23 pm Post subject: |
|
|
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 |
|
| Back to top |
|
 |
olegbl
Joined: 13 Dec 2006 Posts: 48
|
Posted: Thu Oct 09, 2008 1:49 am Post subject: |
|
|
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: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. =) |
|
| Back to top |
|
 |
bmcclure
Joined: 24 Nov 2007 Posts: 774
|
Posted: Thu Oct 09, 2008 2:51 am Post subject: |
|
|
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
(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 |
|
| Back to top |
|
 |
olegbl
Joined: 13 Dec 2006 Posts: 48
|
Posted: Thu Oct 09, 2008 4:56 pm Post subject: |
|
|
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. |
|
| Back to top |
|
 |
bmcclure
Joined: 24 Nov 2007 Posts: 774
|
Posted: Thu Oct 09, 2008 5:33 pm Post subject: |
|
|
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 |
|
| Back to top |
|
 |
olegbl
Joined: 13 Dec 2006 Posts: 48
|
Posted: Thu Oct 09, 2008 5:44 pm Post subject: |
|
|
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) |
|
| Back to top |
|
 |
bmcclure
Joined: 24 Nov 2007 Posts: 774
|
Posted: Fri Oct 10, 2008 2:53 pm Post subject: |
|
|
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 |
|
| Back to top |
|
 |
olegbl
Joined: 13 Dec 2006 Posts: 48
|
Posted: Fri Oct 10, 2008 5:04 pm Post subject: |
|
|
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). |
|
| Back to top |
|
 |
bmcclure
Joined: 24 Nov 2007 Posts: 774
|
Posted: Fri Oct 10, 2008 7:45 pm Post subject: |
|
|
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 |
|
| Back to top |
|
 |
Barney9
Joined: 02 Mar 2007 Posts: 57 Location: Germany
|
Posted: Fri Oct 31, 2008 2:09 pm Post subject: |
|
|
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! |
|
| 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
|