Jump to content
rodiney

check array empty

Recommended Posts

rodiney

I want to do an if in the array.
in my array the value can be 0.
$ Array [0] = 0
as I do to check if array is empty?
if $ array [0] = "" the

endif
It works well?

Share this post


Link to post
Share on other sites
InunoTaishou

Are you checking if the whole array is empty?

#include <Array.au3>

Global const $SORT_DESCENDING = 1
Global $array[] = [3, 2, 1, 5, 1, "Test", "String", 99, 3, 0]
Global $array2[] = [0, 0, 0, 0, "", "", 0, 0]

_ArraySort($array, $SORT_DESCENDING)
_ArraySort($array2, $SORT_DESCENDING)

If ($array[0] or StringLen($array)) Then
    MsgBox("", "", "The first array is not empty")
Else
    MsgBox("", "", "The first array is empty")
EndIf

If ($array2[0] or StringLen($array2)) Then
    MsgBox("", "", "The second array is not empty")
Else
    MsgBox("", "", "The second array is empty")
EndIf

 

  • Like 1

Share this post


Link to post
Share on other sites
czardas
3 hours ago, rodiney said:

It works well?

No it does not work well.

To test the first element, you could use:

If $aArray[0] == "" Then MsgBox(0, "Contents", "nothing")

To test if the array actually contains elements, you should use:

If UBound($aArray) = 0 Then MsgBox(0, "Contents", "zero elements")

These examples will only work with 1D arrays.

Edited by czardas
  • Thanks 1

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

×