Distinguish between Array and another object

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
Archimede
Posts: 540
Joined: 25 Nov 2021, 09:49
Location: Switzerland / Italy

Distinguish between Array and another object

10 May 2024, 03:36

Hallo.
I have a variable
oVar
Then I have an Array and another object:
aArray := [ 1 ]
oObject := InputHook( ... )
Then I can assign it:
oVar := aArray
or
oVar := oObject
Now I need to recognize if oVar contain the array or the other object: is it possible?
User avatar
boiler
Posts: 17189
Joined: 21 Dec 2014, 02:44

Re: Distinguish between Array and another object

10 May 2024, 04:27

Code: Select all

#Requires AutoHotkey v2.0
aArray := [ 1 ]
oObject := InputHook('L1')
oVar := oObject ; aArray
Try
	MsgBox oVar.Has(1) && 'Array'
Catch
	MsgBox 'Input object'
User avatar
boiler
Posts: 17189
Joined: 21 Dec 2014, 02:44

Re: Distinguish between Array and another object

10 May 2024, 05:50

Ah, yes. I keep forgetting we have that now.
Archimede
Posts: 540
Joined: 25 Nov 2021, 09:49
Location: Switzerland / Italy

Re: Distinguish between Array and another object

10 May 2024, 11:42

Type( var )
is very interesting, but is not enough documented on the AutoHotkey manual.
I found this possible return values by Type( var ):

Code: Select all

; "Integer"                                      ; Variable containing an Integer Number.
; "Float"                                        ; Variable containing a Floating point Number or Exponential Number.
; "String"                                       ; Variable containing a String.
; "InputHook"                                    ; Object generated by InputHook( ... )
; "Array"                                        ; Object Sequential Array ( array defined by Array() function ).
; "Map"                                          ; Object Associative Array ( array defined by Map() function ).
If anyone know other possible values, please write it here.

Return to “Ask for Help (v2)”

Who is online

Users browsing this forum: emp00, justha, mikeyww, songdg and 41 guests