Sign in to follow this  
Followers 0
Phaser

Is array empty?

5 posts in this topic

Hi everyone

Simple question (I hope) I have a fixed size [5] 1d array and am pushing and removing values to/from it, when there is a value in it I perform another function with that value but if its empty I don't, simple as that.

How do I check it has something in it?

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

I would do something like this

Local $array[5] = ["T",0,0,1,""]

For $i = 0 To 4 
    If $array[$i] Then
        Msgbox(0,"Array", "Element " & $i & " Is used")
    EndIf
Next
Edited by JohnOne

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites

Dim $array[5] = [0,0,1,0,1]
$iArrayEmpty = ""
for $i = 0 to UBound($array) -1
    if $array[$i] then $iArrayEmpty &= $i & ","
next
if not $iArrayEmpty Then
    MsgBox(0,"","Array is empty")
Else
    $iArrayEmpty = Stringleft($iArrayEmpty,StringLen($iArrayEmpty)-1)
    MsgBox(0,"","Array contains values at position " & $iArrayEmpty)
endif

Dim $array[5] = [0,0,0,0,0]
$iArrayEmpty = ""
for $i = 0 to UBound($array) -1
    if $array[$i] then $iArrayEmpty &= $i & ","
next
if not $iArrayEmpty Then
    MsgBox(0,"","Array is empty")
Else
    $iArrayEmpty = Stringleft($iArrayEmpty,StringLen($iArrayEmpty)-1)
    MsgBox(0,"","Array contains values at position " & $iArrayEmpty)
endif

Share this post


Link to post
Share on other sites

Hi JohnOne

The only problem is, when the array is empty there are no 0's will this still work?

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