davidd31415
Programmer
How can I check if an array is empty?
I've read references to IsEmpty being used with arrays but it always returns false on me. The only solution I've found is to use "if (not array)" but I don't understand how it works exactly... For example:
When I run the program "test" below:
1. The variable tester is true both times it is defined.
2. After s is re-dimensioned, the last two if statements evaluate true (a message box is displayed with the text "it is not empty" followed by one with "it is empty."
From what I see here it looks like 'if (not s)' is only valid when the array is empty- is there a function that returns a true or false value instead of only a true or not true value?
Sub test()
Dim s() As Integer
Dim tester As Boolean
tester = Not s
If (Not s) = True Then MsgBox ("it is empty")
If (Not s) = False Then MsgBox ("it is not empty")
If (Not s) <> True Then MsgBox ("it is not empty")
If (Not s) <> False Then MsgBox ("it is empty")
ReDim Preserve s(0) As Integer
tester = Not (s)
If (Not s) = True Then MsgBox ("it is empty")
If (Not s) = False Then MsgBox ("it is not empty")
If (Not s) <> True Then MsgBox ("it is not empty")
If (Not s) <> False Then MsgBox ("it is empty")
End Sub
I've read references to IsEmpty being used with arrays but it always returns false on me. The only solution I've found is to use "if (not array)" but I don't understand how it works exactly... For example:
When I run the program "test" below:
1. The variable tester is true both times it is defined.
2. After s is re-dimensioned, the last two if statements evaluate true (a message box is displayed with the text "it is not empty" followed by one with "it is empty."
From what I see here it looks like 'if (not s)' is only valid when the array is empty- is there a function that returns a true or false value instead of only a true or not true value?
Sub test()
Dim s() As Integer
Dim tester As Boolean
tester = Not s
If (Not s) = True Then MsgBox ("it is empty")
If (Not s) = False Then MsgBox ("it is not empty")
If (Not s) <> True Then MsgBox ("it is not empty")
If (Not s) <> False Then MsgBox ("it is empty")
ReDim Preserve s(0) As Integer
tester = Not (s)
If (Not s) = True Then MsgBox ("it is empty")
If (Not s) = False Then MsgBox ("it is not empty")
If (Not s) <> True Then MsgBox ("it is not empty")
If (Not s) <> False Then MsgBox ("it is empty")
End Sub