Identify different types of associative arrays

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Albireo
Posts: 1748
Joined: 16 Oct 2013, 13:53

Identify different types of associative arrays

21 Feb 2018, 09:10

Currently, two types of arrays are handled.
My wish is to be able to look at the content with the same function().

My problem right now is to identify the "type" of array.

This is an example, but it seems to work.
Can the identification be done differently? (instead of "For ID... Break...")

Code: Select all

#SingleInstance Force
#NoEnv

; SimpleArray
Color := { Blue:"0x0000FF", Yellow:"0xFFFF00" }

; MultiArray
ArrX1 := { Head1:"AAA", Head2:"BBB", Head3:"CCC" }
ArrX2 := { Head1:"DDD", Head2:"EEE", Head3:"FFF" }
ArrX3 := { Head1:"GGG", Head2:"HHH", Head3:"III" }
ResultArr := { "Res1":ArrX1, "Res2":ArrX2, "Res3":ArrX3 }

; For ID, FieldArray In Color
For ID, FieldArray In ResultArr
{	If StrLen(FieldArray)	; SimpleArray
	{	ArrayType = SimpleArray
		Break
	}
	else	; MultiArray
	{	ArrayType = MultiArray
		Break
	}
}
MsgBox 64, Rad.: %A_LineNumber% -> %A_ScriptName%, ArrayType .: %ArrayType%

ExitApp
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Identify different types of associative arrays

21 Feb 2018, 12:58

- It seems that you want to check if any of the values are objects. Here's a way:

Code: Select all

ArrayType := "SimpleArray"
;for ID, FieldArray in Color
for ID, FieldArray in ResultArr
{	if IsObject(FieldArray)
	{	ArrayType := "MultiArray"
		break
	}
}
- @anyone: Is there a way to get an array's dimension count?
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
Albireo
Posts: 1748
Joined: 16 Oct 2013, 13:53

Re: Identify different types of associative arrays

21 Feb 2018, 14:27

Thank You!

Do not know if I understood your question.
But I did it in this way

Code: Select all

; Count all Records and Fields (to view in the summary) and get the type of the Array
For ID, FieldArray In ObjName
{	If StrLen(FieldArray)
	{	ArrayType := "SimpleArray"
		FieldCount += 1
		RecCount = 1
	}
	else
	{	ArrayType := "MultiArray"
		If A_Index = 1
		{	For ID2, Fields In FieldArray
				FieldCount += 1
		}
		RecCount += 1
	}
	MsgBox  ArrayType .: %ArrayType% `nFields .: %FieldCount% `nRecords .: %RecCount%
}
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Identify different types of associative arrays

21 Feb 2018, 15:30

- For my question, I've started a new thread. Cheers.
objects: get dimensions - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=44568
- Your question was essentially: does an object have 1 or more dimensions. My question was: how many dimensions does an object have.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 254 guests