Results 1 to 10 of 10

Thread: parseing an array

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2000
    Posts
    258

    Question

    Im trying to Check a string against an array.Its Basicaly
    If the string is in the array then stop .
    So I Loop through the array and compare , thats fine .
    But When the array is empty I get a script out of bounds error . Is there a way around this ?
    Visual Basic 6 SP4 on win98se

    QUIT THE RAT RACE BECAUSE YOUR MESSING THE WORLD UP !!!!!

  2. #2
    Guest
    try adding
    Code:
    On Error Resume Next
    at the beginning of the sub.

  3. #3
    Guest
    I am sure there is a way so you dont get any error, but this is the lazy way out.

  4. #4
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Start your loop with
    Code:
    Do Until X>Ubound(array)
    or end it with
    Code:
    Loop until X>=ubound(array)
    or have a for next loop
    Code:
    For X=lbound(array) to ubound(array)
    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.

  5. #5
    Guest
    I recomend the For...Next Loop, those are my favorite

  6. #6
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    I guess you could have a Goto
    Code:
    1:
    
    X=X+1
    
    If ubound(array)>=x then goto 1
    But i don't recommend it, For Next is my favourite but Do, or While Loop are useful too
    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.

  7. #7
    Guru Yonatan's Avatar
    Join Date
    Apr 1999
    Location
    Israel
    Posts
    892

    Exclamation I guess you shouldn't

    The Goto command is NEVER recommended, except when it's completely impossible to not use it.
    There is only one such case:
    On Error Goto Oops

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2000
    Posts
    258
    Originally posted by kedaman
    Start your loop with
    Code:
    Do Until X>Ubound(array)
    or end it with
    Code:
    Loop until X>=ubound(array)
    or have a for next loop
    Code:
    For X=lbound(array) to ubound(array)
    The Problem lies right when I call
    this = ubound(usr)
    due to the fact that usr() has no Ubound if its empty

  9. #9
    Lively Member
    Join Date
    Jul 2000
    Posts
    104
    Code:
    Private Sub ParseArray()
        On Error GoTo ArrayErr
    
        this = UBound(usr) 
        'do whatever
    
        Exit Sub
    ArrayErr:
        If Err.Number = 9 Then
           Call MsgBox("Empty array", vbInformation)
        Else
           'oops
        End If
    End Sub

  10. #10
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Here's my not so(yet) famous fake ubound function, actually it's the get part of a property
    Code:
    Property Get UUbound(Uarray)
        UUbound = -1
        On Error Resume Next
        UUbound = UBound(Uarray)
    End Property
    It will return the upperbound if intialized, or -1 if not. Therefore it wont go trough the loop at all
    [code]
    For X=0 to uubound(array)

    next x
    [code]
    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.

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