Page 1 of 1

Distinguish between Array and another object

Posted: 10 May 2024, 03:36
by Archimede
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?

Re: Distinguish between Array and another object

Posted: 10 May 2024, 04:27
by boiler

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'

Re: Distinguish between Array and another object

Posted: 10 May 2024, 04:48
by thqby
Why not use Type(var)?

Re: Distinguish between Array and another object

Posted: 10 May 2024, 05:50
by boiler
Ah, yes. I keep forgetting we have that now.

Re: Distinguish between Array and another object

Posted: 10 May 2024, 11:42
by Archimede
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.