Results 1 to 20 of 20

Thread: Is an array empty???

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2000
    Location
    Aberdeen
    Posts
    4

    Question

    Hi All

    Is there anywya of knowing whether an array is empty or not. If there is can you tell me how I could do this.

    Thanks

  2. #2
    Frenzied Member Jop's Avatar
    Join Date
    Mar 2000
    Location
    Amsterdam, the Netherlands
    Posts
    1,986
    Code:
    If UBound(MyArray) = 0 Then MsgBox "EMPTY!"
    Jop - validweb.nl

    Alcohol doesn't solve any problems, but then again, neither does milk.

  3. #3
    Addicted Member
    Join Date
    Apr 1999
    Location
    Atlanta
    Posts
    145
    Dim aMyArray() As String
    Dim i As Integer
    Dim vIsEmptyTF As Boolean

    For i = LBound(aMyArray()) To UBound(aMyArray())
    If aMyArray(i) <> "" Then
    vIsEmptyTF = False
    End If
    Next i

  4. #4
    Frenzied Member Jop's Avatar
    Join Date
    Mar 2000
    Location
    Amsterdam, the Netherlands
    Posts
    1,986
    We have a different defenition of empty
    Jop - validweb.nl

    Alcohol doesn't solve any problems, but then again, neither does milk.

  5. #5
    Addicted Member
    Join Date
    Apr 1999
    Location
    Atlanta
    Posts
    145
    I guess we do. My Bad vIsEmptyTF = true
    I like your way better anyway!

    Joe

  6. #6
    Guest
    If you are dealing with numeric expressions, use 0 instead of "".
    Code:
    If aMyArray(i) <> 0 Then

  7. #7
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Code:
    on error resume next
    test=aMyarray(i)
    if err=9 then msgbox "empty array"
    on error goto 0
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  8. #8
    Addicted Member
    Join Date
    Oct 2000
    Location
    Vienna/Austria
    Posts
    132
    Hi jo 201 !!!

    If you want do know if the array is initialized
    (dim myarray(10))
    then the best way to check this out is, kedaman approach.

    if you wnat to know if the array have values, then
    you can use Megatron or courchjo approach, depends which
    data type your array is.

    -cu TheOnly

  9. #9
    Lively Member Ceri's Avatar
    Join Date
    Sep 2000
    Posts
    72

    Easier Way

    You can use the IsEmpty call if you want to see if an array has been initialized or not.

    e.g.

    [CODE]
    If IsEmpty(MyArray) Then
    'do something
    Else
    'do something else
    End If

  10. #10
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Empty is a value only variants can have.
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  11. #11
    Frenzied Member Jop's Avatar
    Join Date
    Mar 2000
    Location
    Amsterdam, the Netherlands
    Posts
    1,986
    Not sure about that keda!
    Code:
    Private Sub Command1_Click()
    Dim str$
    str = ""
    MsgBox str = Empty
    str = "haha keda's wrong for a change ;P"
    MsgBox str = Empty
    End Sub
    Jop - validweb.nl

    Alcohol doesn't solve any problems, but then again, neither does milk.

  12. #12
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Aaah! jop got me! Actually hehe , not really, it convert empty to a nullstring before assigning it to str
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  13. #13
    Frenzied Member Jop's Avatar
    Join Date
    Mar 2000
    Location
    Amsterdam, the Netherlands
    Posts
    1,986
    I'll never be better than Kedaman
    Jop - validweb.nl

    Alcohol doesn't solve any problems, but then again, neither does milk.

  14. #14
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    kedeman's way or this way, similar.
    ceri's tested ok as well

    Jop, courchjo, Megatron's will creat an error
    on execution of code.
    Code:
    'Check to see if an array is empty
    'avoid error on trying to view
    
    On Error GoTo QuitNow:
    
    Debug.Print UBound(myArray)
    On Error GoTo 0
    Exit Sub
    QuitNow:
    Debug.Print "Error,no dimension for array!"

    [Edited by HeSaidJoe on 01-12-2001 at 12:01 PM]
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  15. #15
    Frenzied Member Jop's Avatar
    Join Date
    Mar 2000
    Location
    Amsterdam, the Netherlands
    Posts
    1,986
    The error nr for "Subscript out of range" is 9, so if your going to implement that in your project, check for Err.Number 9 to make sure you capture the right error.
    Jop - validweb.nl

    Alcohol doesn't solve any problems, but then again, neither does milk.

  16. #16
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    Code:
    'Jop, not if you use it like this as there is only
    'one error that can happen inside the function.
    
    Public Function CheckArray(x As Variant) As Boolean
        CheckArray = True
        'Check to see if my array is empty
            On Error GoTo Quitnow:
            
            Debug.Print UBound(x)
            On Error GoTo Quitnow:
            Exit Function
    Quitnow:
           CheckArray = False
    End Function
    
    Private Sub Form_Load()
        x = CheckArray(myArray)
        If x Then
            MsgBox "Carry On"
        Else
           MsgBox "Empty"
            Exit Sub
        End If
    
    End Sub
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  17. #17
    Frenzied Member Jop's Avatar
    Join Date
    Mar 2000
    Location
    Amsterdam, the Netherlands
    Posts
    1,986
    Well Wayne, that's what I said
    Well I should have said:

    [qoute]
    if your going to implement that in your project (which probably has more error(handlers)), check for Err.Number 9 to make sure you capture the right error.
    [/quote]
    Jop - validweb.nl

    Alcohol doesn't solve any problems, but then again, neither does milk.

  18. #18
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    Jop
    I'm just playing with your emotions...slow day at the office.
    :
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  19. #19
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Hehe what are you doing guys!? this is an old thread, i noticed, who picked it up?
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  20. #20
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    TheOnly
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width