Associative Array inside a Regular Array

Post a reply


In an effort to prevent automatic submissions, we require that you type the text displayed into the field underneath.
Smilies
:D :) ;) :( :o :shock: :? 8-) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :!: :?: :idea: :| :mrgreen: :geek: :ugeek: :arrow: :angel: :clap: :crazy: :eh: :lolno: :problem: :shh: :shifty: :sick: :silent: :think: :thumbup: :thumbdown: :salute: :wave: :wtf: :yawn: :facepalm: :bravo: :dance: :beard: :morebeard: :xmas: :HeHe: :trollface: :cookie: :rainbow: :monkeysee: :monkeysay: :happybday: :headwall: :offtopic: :superhappy: :terms: :beer:
View more smilies

BBCode is ON
[img] is OFF
[flash] is OFF
[url] is ON
Smilies are ON

Topic review
   

Expand view Topic review: Associative Array inside a Regular Array

Re: Associative Array inside a Regular Array

Post by gilliduck » 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.

Re: Associative Array inside a Regular Array

Post by lexikos » 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.

Re: Associative Array inside a Regular Array

Post by gilliduck » 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!

Re: Associative Array inside a Regular Array

Post by TLM » 23 Aug 2015, 16:29

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

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

Re: Associative Array inside a Regular Array

Post by TLM » 23 Aug 2015, 16:06

hrm that's odd I get msgbox's for each item
Image

Re: Associative Array inside a Regular Array

Post by gilliduck » 23 Aug 2015, 16:02

That doesn't seem to do anything. It runs, then exits without ever generating a MsgBox.

Re: Associative Array inside a Regular Array

Post by TLM » 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]GeSHi © Codebox Plus

Associative Array inside a Regular Array

Post by gilliduck » 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]GeSHi © Codebox Plus


Top