Pushing "key:children" into array Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
HeXaDeCiMaToR
Posts: 155
Joined: 08 Feb 2021, 12:42

Pushing "key:children" into array

24 Jun 2021, 02:54

I'm trying to create an object that would look a little like:

Code: Select all

{"ReviewLog":{"%FileNumber%":{"TimeStamp":"%CurrentDate%","Lead":"%LeadValuator%","Tracking":"%Tracking%","Options":"%Options%","PV":"%PV%","2ndSource":"%SecSource%","Title":"%Brand%","Distance":"%Distance%","ACV":"%ACV%","PriceTables":"%PriceTables%","CompResearch":"%CompResearch%","SpecialInst":"%SpecialInst%","PriceMargin":"%PriceMargin%","Comments":"%Comments%","AdditionalComments":"%AddtionalComments%"}}}
I've thought about FileAppend, but that has its issues with opening and closing the array whenever I need to access it, or I'm done using it. (and I want to access it on the fly)

So, Now I'm trying to "PUSH" the values into the array with this:

Code: Select all

LoggedFile.Push(ReviewLog(%FileNumber%("TimeStamp":%CurrentDate%,"Lead":%LeadValuator%,"Tracking":%Tracking%,"Options":%Options%,"PV":%PV%,"2ndSource":%SecSource%,"Title":%Brand%,"Distance":%Distance%,"ACV":%ACV%,"PriceTables":%PriceTables%,"CompResearch":%CompResearch%,"SpecialInst":%SpecialInst%,"PriceMargin":%PriceMargin%,"Comments":%Comments%,"AdditionalComments":%AddtionalComments%)
...and AHK doesn't like that syntax at ALL!!

I've read the AHK documentation on Objects and Jeeswg's Objects Tutorial, but I didn't see a smoking gun on how to achieve this. Has anybody successfully done this?
HeXaDeCiMaToR
Posts: 155
Joined: 08 Feb 2021, 12:42

Re: Pushing "key:children" into array

24 Jun 2021, 03:02

Could I do:

Code: Select all

LoggedFile:=[]
LoggedFile[ReviewLog]:=%FileNumber%
LoggedFile.ReviewLog[1]:=["TimeStamp":"%CurrentDate%","Lead":"%LeadValuator%","Tracking":"%Tracking%","Options":"%Options%","PV":"%PV%","2ndSource":"%SecSource%","Title":"%Brand%","Distance":"%Distance%","ACV":"%ACV%","PriceTables":"%PriceTables%","CompResearch":"%CompResearch%","SpecialInst":"%SpecialInst%","PriceMargin":"%PriceMargin%","Comments":"%Comments%","AdditionalComments":"%AddtionalComments%"]
??
User avatar
Hellbent
Posts: 2109
Joined: 23 Sep 2017, 13:34

Re: Pushing "key:children" into array

24 Jun 2021, 03:08

This part here suggests that you are calling a function and then in that function call you are calling another function.

Code: Select all

ReviewLog(%FileNumber%(
sort of like this.

Code: Select all

MyArray.Push( MyFunction1( MyFunction2( "Something" ) ) )

MyFunction1( Input ){
   return blahblahblah
   
}

MyFunction2( Input ){
   return somethingProfound
   
}
It doesn't look like that is what you are actually trying to do.

I think this is more of along the lines of what you want.

Code: Select all

MyArray := []
MyArray.Push({"ReviewLog":{"%FileNumber%":{"TimeStamp":"%CurrentDate%","Lead":"%LeadValuator%","Tracking":"%Tracking%","Options":"%Options%","PV":"%PV%","2ndSource":"%SecSource%","Title":"%Brand%","Distance":"%Distance%","ACV":"%ACV%","PriceTables":"%PriceTables%","CompResearch":"%CompResearch%","SpecialInst":"%SpecialInst%","PriceMargin":"%PriceMargin%","Comments":"%Comments%","AdditionalComments":"%AddtionalComments%"}}})


;OR
;**********************************************************

obj := {"ReviewLog":{"%FileNumber%":{"TimeStamp":"%CurrentDate%","Lead":"%LeadValuator%","Tracking":"%Tracking%","Options":"%Options%","PV":"%PV%","2ndSource":"%SecSource%","Title":"%Brand%","Distance":"%Distance%","ACV":"%ACV%","PriceTables":"%PriceTables%","CompResearch":"%CompResearch%","SpecialInst":"%SpecialInst%","PriceMargin":"%PriceMargin%","Comments":"%Comments%","AdditionalComments":"%AddtionalComments%"}}}

MyArray := []
MyArray.Push( obj )

Last edited by Hellbent on 24 Jun 2021, 03:09, edited 1 time in total.
HeXaDeCiMaToR
Posts: 155
Joined: 08 Feb 2021, 12:42

Re: Pushing "key:children" into array

24 Jun 2021, 03:18

I think I have to declare the new key like:

Code: Select all

LoggedFiles:={}
LoggedFiles[ReviewFiles]:={}
LoggedFiles[ReviewFiles].TimeStamp:=%CurrentDate%
LoggedFiles[ReviewFiles].Lead:=%LeadValuator%
...and so on
HeXaDeCiMaToR
Posts: 155
Joined: 08 Feb 2021, 12:42

Re: Pushing "key:children" into array

24 Jun 2021, 03:22

Sorry @Hellbent I just saw your post. I think I'm going to try your ideas. I'm using your "Dock It" script, and I've watched almost all of your tutorials. I love your work and your contribution to the community. Thank you.
User avatar
Hellbent
Posts: 2109
Joined: 23 Sep 2017, 13:34

Re: Pushing "key:children" into array

24 Jun 2021, 03:27

HeXaDeCiMaToR wrote:
24 Jun 2021, 03:18
I think I have to declare the new key like:

Code: Select all

LoggedFiles:={}
LoggedFiles[ReviewFiles]:={}
LoggedFiles[ReviewFiles].TimeStamp:=%CurrentDate%
LoggedFiles[ReviewFiles].Lead:=%LeadValuator%
...and so on
You can also do something similar like this.

Code: Select all

ReviewLog := { "%FileNumber%": { "TimeStamp":           "%CurrentDate%"
                               , "Lead":                "%LeadValuator%"
                               , "Tracking":            "%Tracking%"
                               ,"Options":              "%Options%"
                               ,"PV":                   "%PV%"
                               ,"2ndSource":            "%SecSource%"
                               ,"Title":                "%Brand%"
                               ,"Distance":             "%Distance%"
                               ,"ACV":                  "%ACV%"
                               ,"PriceTables":          "%PriceTables%"
                               ,"CompResearch":         "%CompResearch%"
                               ,"SpecialInst":          "%SpecialInst%"
                               ,"PriceMargin":          "%PriceMargin%"
                               ,"Comments":             "%Comments%"
                               ,"AdditionalComments":   "%AddtionalComments%"   } }
Preference is up to you.
HeXaDeCiMaToR wrote:
24 Jun 2021, 03:22
Sorry @Hellbent I just saw your post. I think I'm going to try your ideas. I'm using your "Dock It" script, and I've watched almost all of your tutorials. I love your work and your contribution to the community. Thank you.

TY :thumbup:
HeXaDeCiMaToR
Posts: 155
Joined: 08 Feb 2021, 12:42

Re: Pushing "key:children" into array

24 Jun 2021, 03:35

So AHK liked the syntax, but when I tested it:

Code: Select all

LoggedFile:=[]
LoggedFile.Push({"ReviewLog":{"%FileNumber%":{"TimeStamp":"%CurrentDate%","Lead":"%LeadValuator%","Tracking":"%Tracking%","Options":"%Options%","PV":"%PV%","2ndSource":"%SecSource%","Title":"%Brand%","Distance":"%Distance%","ACV":"%ACV%","PriceTables":"%PriceTables%","CompResearch":"%CompResearch%","SpecialInst":"%SpecialInst%","PriceMargin":"%PriceMargin%","Comments":"%Comments%","AdditionalComments":"%AddtionalComments%"}}})
for key,val in LoggedFile
		MsgBox,,Test, % key ":" val
return
It returns "1: "
image.png
image.png (1.35 KiB) Viewed 466 times
shouldn't that show me "ReviewLog" are the val you %FileNumber%?
HeXaDeCiMaToR
Posts: 155
Joined: 08 Feb 2021, 12:42

Re: Pushing "key:children" into array

24 Jun 2021, 03:36

Aw shoot! I just saw it []
User avatar
Hellbent
Posts: 2109
Joined: 23 Sep 2017, 13:34

Re: Pushing "key:children" into array  Topic is solved

24 Jun 2021, 03:39

One more

Code: Select all

ReviewLog := {}
ReviewLog["%FileNumber%"] := { "TimeStamp":           "%CurrentDate%"
                               , "Lead":                "%LeadValuator%"
                               , "Tracking":            "%Tracking%"
                               ,"Options":              "%Options%"
                               ,"PV":                   "%PV%"
                               ,"2ndSource":            "%SecSource%"
                               ,"Title":                "%Brand%"
                               ,"Distance":             "%Distance%"
                               ,"ACV":                  "%ACV%"
                               ,"PriceTables":          "%PriceTables%"
                               ,"CompResearch":         "%CompResearch%"
                               ,"SpecialInst":          "%SpecialInst%"
                               ,"PriceMargin":          "%PriceMargin%"
                               ,"Comments":             "%Comments%"
                               ,"AdditionalComments":   "%AddtionalComments%"   }
I get the feeling that some of the "%something%" may not be what you think it is.

So perhaps what you had wanted is more like this?

Code: Select all

ReviewLog := []
ReviewLog[FileNumber] := {  "TimeStamp":           CurrentDate
                        ,   "Lead":                LeadValuator
                        ,   "Tracking":            Tracking
                        ,   "Options":             Options
                        ,   "PV":                  PV
                        ,   "2ndSource":           SecSource
                        ,   "Title":               Brand
                        ,   "Distance":            Distance
                        ,   "ACV":                 ACV
                        ,   "PriceTables":         PriceTables
                        ,   "CompResearch":        CompResearch
                        ,   "SpecialInst":         SpecialInst
                        ,   "PriceMargin":         PriceMargin
                        ,   "Comments":            Comments
                        ,   "AdditionalComments":  AddtionalComments   }
User avatar
Hellbent
Posts: 2109
Joined: 23 Sep 2017, 13:34

Re: Pushing "key:children" into array

24 Jun 2021, 03:40

Just seen your last post. See the second code box to see if that is what you were really trying to do.
User avatar
Hellbent
Posts: 2109
Joined: 23 Sep 2017, 13:34

Re: Pushing "key:children" into array

24 Jun 2021, 03:43

using a for loop with your "%stuff%"

Code: Select all

ReviewLog := {}
ReviewLog["%FileNumber%"] := { "TimeStamp":           "%CurrentDate%"
                               , "Lead":                "%LeadValuator%"
                               , "Tracking":            "%Tracking%"
                               ,"Options":              "%Options%"
                               ,"PV":                   "%PV%"
                               ,"2ndSource":            "%SecSource%"
                               ,"Title":                "%Brand%"
                               ,"Distance":             "%Distance%"
                               ,"ACV":                  "%ACV%"
                               ,"PriceTables":          "%PriceTables%"
                               ,"CompResearch":         "%CompResearch%"
                               ,"SpecialInst":          "%SpecialInst%"
                               ,"PriceMargin":          "%PriceMargin%"
                               ,"Comments":             "%Comments%"
                               ,"AdditionalComments":   "%AddtionalComments%"   }

for k, v in ReviewLog["%FileNumber%"]
   msgbox, % k " :  " v
HeXaDeCiMaToR
Posts: 155
Joined: 08 Feb 2021, 12:42

Re: Pushing "key:children" into array

24 Jun 2021, 03:45

I think you're right... I don't think I even need the "LoggedFile" layer either (like you wrote)
HeXaDeCiMaToR
Posts: 155
Joined: 08 Feb 2021, 12:42

Re: Pushing "key:children" into array

24 Jun 2021, 03:50

Your second example made sense to me after I read it. I questioned "FileNumber" not being enclosed in "%" but I went forward without and it works like a charm. Thank you again!

I'm sure I can find it online, but what method have you found is best for storing objects on Exit?
User avatar
Hellbent
Posts: 2109
Joined: 23 Sep 2017, 13:34

Re: Pushing "key:children" into array

24 Jun 2021, 04:01

HeXaDeCiMaToR wrote:
24 Jun 2021, 03:50
Your second example made sense to me after I read it. I questioned "FileNumber" not being enclosed in "%" but I went forward without and it works like a charm. Thank you again!

I'm sure I can find it online, but what method have you found is best for storing objects on Exit?
I haven't had a need to do it very often, but I like using a ini file.
It has structure built into it.

Code: Select all

[section]
key=value

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 109 guests