Sign in to follow this  
Followers 0
gamerman2360

Vars & Arrays

8 posts in this topic

#1 ·  Posted (edited)

IsDeclared("") is not working with arrays. I have run a few tests on this problem and have found something:

Dim $test[5][5][7]
MsgBox(0, "Test", IsDeclared("test[1][1][0]")); Returns 0
MsgBox(0, "Test", Eval("test[1][1][0]")); Returns ""
MsgBox(0, "Test", Assign("test[1][1][0]", 2)); Returns 1
MsgBox(0, "Test", Execute("$test[1][1][0]+1")); Returns 1
MsgBox(0, "Test", Eval("test[1][1][0]")); Returns 2
MsgBox(0, "Test", $test[1][1][0])); Returns ""
It seems that vars can be used with '[' and ']' in the name but only if Assign()ed and can only be retrieved with Eval(). But that means arrays can't be used in any of these functions (except execute()). Is there a way to get past this?

Edited by gamerman2360

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Best I can do is:

Func _IsArrayDeclared($arrayname)
    If Execute("$" & $arrayname) <> "" Then Return 1
    Return 0
EndFunc
But that still dosn't get the arrays that = "". If I try to test if an array = "" it will have a fatial error.

[edit]

Is there a way to get it to handle an autoit error differently during this function?

Edited by gamerman2360

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Func IsArrayDeclared($arrayname)
   If $arrayname <> "" Then 
      If Execute("$" & $arrayname) <> "" Then 
         Return 1
      EndIf
   EndIf
   Return 0
EndFunc

Perhaps this?

Edited by AutoIt Smith

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

If $Test[1][1][0] <> '' Then

IsDeclared() returns True because you have declared the array. After declaring the array you can only test whether each element has content using the method above.

Edit: Typo.

Edited by LxP

Share this post


Link to post
Share on other sites

@AutoIt Smith

I ment if the array contained a blank string. Execute will return what the array is without causing an error if there was nothing, right? If it wasn't declared it returns "" and if it = "" it will return it so there would be no way to tell them apart

@Lxp

IsDeclared("test[1][1][0]") returns 0

Do you mean IsDeclared("test") returns 1? I'll test that...

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

IsDeclared("test") does return 1 but I guess, if you use UBound() several times in the right order, IsDeclared() for arrays isn't needed.

Edited by gamerman2360

Share this post


Link to post
Share on other sites

Yes, UBound() can be used to determine how many dimensions an array has and the length of each dimension. There's no way however to determine whether each individual element had been set other than seeing whether it's empty (i.e. equal to '').

Share this post


Link to post
Share on other sites

There we go!

Func _IsArrayDeclared($array, $indexes)
    $indexes = StringSplit($indexes, ",")
    $check = 0
    If $indexes[0] == UBound($array, 0) Then $check += 1
    For $i = 0 To UBound($array, 0)
        If $indexes[$i] < UBound($array, $i) Then $check +=1
    Next
    If $check == UBound($array, 0) + 1 Then Return 1
EndFunc

Dim $array[3][6][5][9]
MsgBox(0, "Test", _IsArrayDeclared($array, "2,5,4,8"))

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0