insert variable as a key in dictionary Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Ernestas
Posts: 33
Joined: 16 Apr 2018, 02:07

insert variable as a key in dictionary

19 Jun 2020, 04:47

Hello guys,

I was wondering why does it give string as a key in the dictionary. How to insert variable to the dictionary as a key. Would really appreciate your help guys!!

Code: Select all

#z::

mainData := {}

tempAcc := 8696796666666
tempBookingDate := "booking date 1"
tempAmount := "amount 100"

if !mainData.haskey(tempAcc)
{
	row := 1
	mainData.insert(tempAcc, {row : [tempBookingDate, tempAmount]})
}

for account, accountRowData in mainData 
{
	msgbox, % account
	
	for row, rowData in accountRowData 
	{
		MsgBox, % "row: " row
		
		for index, rowListData in rowData 
		{
			msgbox, % "data in Row: " rowListData
		}
	}
}
	
return
Last edited by BoBo on 19 Jun 2020, 04:50, edited 1 time in total.
Reason: Changed [c][/c]-tags to full blown [code][/code]-tags.
User avatar
boiler
Posts: 17389
Joined: 21 Dec 2014, 02:44

Re: insert variable as a key in dictionary  Topic is solved

19 Jun 2020, 05:22

Associative array documentation wrote:...to use a variable as a key, it must be enclosed in parentheses
See documentation on associative arrays.

So your line changes to this:

Code: Select all

mainData.insert(tempAcc, {(row) : [tempBookingDate, tempAmount]})

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot], oktavimark, Rohwedder and 252 guests