Associative Array inside a Regular Array

Get help with using AutoHotkey and its commands and hotkeys
gilliduck
Posts: 265
Joined: 06 Oct 2014, 15:01

Associative Array inside a Regular Array

23 Aug 2015, 15:20

I'd like the below code to end up making an array that each index contains an associative array containing the values of Name, Price, Option, Quantity & Stock. Basically Array := [{Name:Something,Price:$129.99,Option:Brown,Stock:In Stock},{Name:SomethingElse,Price:$119.99,Option:,Stock:Limited Quantity}. I'm just not sure how to create it. Someone mind tossing me a small bone?

FYI if you run the script, prepare for the UrlDownloadToFile to take 30 seconds or more.

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

User avatar
TLM
Posts: 1146
Joined: 01 Oct 2013, 07:52

Re: Associative Array inside a Regular Array

23 Aug 2015, 15:55

gilliduck I noticed you left irc before I got to show you this..
you don't have to save to file and use a bunch of substr() things, you can use dom to get the info you're after
http://p.ahkscript.org/?p=0d45fd

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

Image
gilliduck
Posts: 265
Joined: 06 Oct 2014, 15:01

Re: Associative Array inside a Regular Array

23 Aug 2015, 16:02

That doesn't seem to do anything. It runs, then exits without ever generating a MsgBox.
User avatar
TLM
Posts: 1146
Joined: 01 Oct 2013, 07:52

Re: Associative Array inside a Regular Array

23 Aug 2015, 16:06

hrm that's odd I get msgbox's for each item
Image
Image
User avatar
TLM
Posts: 1146
Joined: 01 Oct 2013, 07:52

Re: Associative Array inside a Regular Array

23 Aug 2015, 16:29

that aside for a sec,
here's an example of inserting associative arrays into simple arrays

Code: [Select all] [Download] GeSHi © Codebox Plus

arr := []
arr[ 1 ] := {a:"dog",b:"cat",c:"bird"}
arr[ 2 ] := {a:"fish",b:"snake",c:"frog"}

for i, obj in arr
for key, animal in obj
msgbox % "Array: " i "`nKey: " key "`nAnimal: " animal
Image
gilliduck
Posts: 265
Joined: 06 Oct 2014, 15:01

Re: Associative Array inside a Regular Array

23 Aug 2015, 16:52

Yeah, I've got no explanation. I can see it run, but then it eventually exits without ever generating anything. I'll play with it more. Thanks for the Array info!
lexikos
Posts: 5456
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Re: Associative Array inside a Regular Array

24 Aug 2015, 02:02

Basically Array := [{Name:Something,Price:$129.99,Option:Brown,Stock:In Stock},{Name:SomethingElse,Price:$119.99,Option:,Stock:Limited Quantity}
Add quote marks around the strings, append the missing ']', and you'll have it...

...but I guess your actual usage will involve adding items one at a time, like TLM demonstrated.
gilliduck
Posts: 265
Joined: 06 Oct 2014, 15:01

Re: Associative Array inside a Regular Array

24 Aug 2015, 05:42

Once I had the basic syntax down it made perfect sense. Inside a loop dict[A_Index] := {Item:Name, Price:Price, Option:Option, Stock:Stock} with all values being variables, so no need for quotes to define strings. It's so simple yet I just couldn't see it in the moment.

Return to “Ask For Help”

Who is online

Users browsing this forum: ozzynotwood and 49 guests