gamerman2360 Posted December 5, 2005 Share Posted December 5, 2005 (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 December 5, 2005 by gamerman2360 Link to comment Share on other sites More sharing options...
gamerman2360 Posted December 5, 2005 Author Share Posted December 5, 2005 (edited) Best I can do is: Func _IsArrayDeclared($arrayname) If Execute("$" & $arrayname) <> "" Then Return 1 Return 0 EndFuncBut 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 December 5, 2005 by gamerman2360 Link to comment Share on other sites More sharing options...
themax90 Posted December 5, 2005 Share Posted December 5, 2005 (edited) Func IsArrayDeclared($arrayname) If $arrayname <> "" Then If Execute("$" & $arrayname) <> "" Then Return 1 EndIf EndIf Return 0 EndFunc Perhaps this? Edited December 5, 2005 by AutoIt Smith Link to comment Share on other sites More sharing options...
LxP Posted December 5, 2005 Share Posted December 5, 2005 (edited) If $Test[1][1][0] <> '' ThenIsDeclared() 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 December 5, 2005 by LxP Link to comment Share on other sites More sharing options...
gamerman2360 Posted December 5, 2005 Author Share Posted December 5, 2005 @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... Link to comment Share on other sites More sharing options...
gamerman2360 Posted December 5, 2005 Author Share Posted December 5, 2005 (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 December 5, 2005 by gamerman2360 Link to comment Share on other sites More sharing options...
LxP Posted December 5, 2005 Share Posted December 5, 2005 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 ''). Link to comment Share on other sites More sharing options...
gamerman2360 Posted December 5, 2005 Author Share Posted December 5, 2005 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")) Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now