Jump to content

check array empty


rodiney
 Share

Recommended Posts

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

 

Link to comment
Share on other sites

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
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...