mike Posted January 9, 2009 Share Posted January 9, 2009 how to compare array Variable with non array variable autoit always show error Global $UFO[3] Global $Frog $UFO[1] = 20 $UFO[2] = 45 $GM = _MemoryPointerRead($APP_BASE_ADDRESS, $PROCESS_INFORMATION, $UFO) $frog = 2000 * 2 + 100 IF $GM[1] < $frog then MsgBox(0, "done", "GM < frog") endif with the script above, i always get error "Subscript used with non-Array variable" any other way to compare that ? Link to comment Share on other sites More sharing options...
jvanegmond Posted January 9, 2009 Share Posted January 9, 2009 (edited) If IsArray($GM) Then IF $GM[1] < $frog then MsgBox(0, "done", "GM < frog") endif EndIfoÝ÷ ØäZºÚ"µÍYÐ^J ÌÍÑÓJH[XÝ[ ÌÍÑÓJH ÝÏHH[Q ÌÍÑÓVÌWH È ÌÍÙÙÈ[ÙÐÞ ][ÝÙÛI][ÝË ][ÝÑÓH ÈÙÉ][ÝÊB[Y[Y Edited January 9, 2009 by Manadar github.com/jvanegmond Link to comment Share on other sites More sharing options...
mike Posted January 9, 2009 Author Share Posted January 9, 2009 correct me if i am wrong .. but .. isArray is use for checking if the variable is Array or not .. is it true ? on my script ..i already know which is Array and which is not array problem is : i must compare that one (Array variable) with Non-Array variable.. any idea how to make it comparable without having error : "Subscript used with non-Array variable" ? Link to comment Share on other sites More sharing options...
PsaltyDS Posted January 9, 2009 Share Posted January 9, 2009 correct me if i am wrong .. but .. isArray is use for checking if the variable is Array or not .. is it true ? on my script ..i already know which is Array and which is not array problem is : i must compare that one (Array variable) with Non-Array variable.. any idea how to make it comparable without having error : "Subscript used with non-Array variable" ?No, you ASSUMED you knew it was an array because you ASSUMED the function _MemoryPointerRead() always returned an array, even if it failed (also that the array had at least 2 elements). The tests Manadar posted handles failure of _MemoryPointerRead(). Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
mike Posted January 10, 2009 Author Share Posted January 10, 2009 @Manadar & PsaltyDS thanks .. can u tell this script's when it failed or success ? ; if $GM is array then do the script below ? if $GM is not Array then ? If IsArray($GM) and Ubound($GM) >= 1 Then IF $GM[1] < $frog then MsgBox(0, "done", "GM < frog") endif EndIf thanks in advance Link to comment Share on other sites More sharing options...
PsaltyDS Posted January 10, 2009 Share Posted January 10, 2009 @Manadar & PsaltyDS thanks .. can u tell this script's when it failed or success ? ; if $GM is array then do the script below ? if $GM is not Array then ? If IsArray($GM) and Ubound($GM) >= 1 Then IF $GM[1] < $frog then MsgBox(0, "done", "GM < frog") endif EndIf thanks in advance That's close, and you've got the right idea. AutoIt arrays are 0-based so [1] is the second element, and if you want to make sure there is a [1] element you need Ubound() >= 2. Proper error handling requires knowing what your function calls might return, both for success and fail. For failure some might return 0 or -1 instead of an array, and some might return an empty array and set @error. There are too many variations to write one test for all cases. You have to get to know the functions you are using. Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
mike Posted January 12, 2009 Author Share Posted January 12, 2009 That's close, and you've got the right idea. AutoIt arrays are 0-based so [1] is the second element, and if you want to make sure there is a [1] element you need Ubound() >= 2. Proper error handling requires knowing what your function calls might return, both for success and fail. For failure some might return 0 or -1 instead of an array, and some might return an empty array and set @error. There are too many variations to write one test for all cases. You have to get to know the functions you are using. thanks PsaltyDS and Manadar its solved 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