Jump to content

Is array empty?


Recommended Posts

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?

Link to comment
Share on other sites

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.

Link to comment
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

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...