Jump to content
Sign in to follow this  
mike

Array VS non-array compare with <

Recommended Posts

mike

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 ?

Share this post


Link to post
Share on other sites
jvanegmond

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 by Manadar

Share this post


Link to post
Share on other sites
mike

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" ?

Share this post


Link to post
Share on other sites
PsaltyDS

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

Share this post


Link to post
Share on other sites
mike

@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

Share this post


Link to post
Share on other sites
PsaltyDS

@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

Share this post


Link to post
Share on other sites
mike

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 :o

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  

×