|
-
Aug 17th, 2000, 10:30 PM
#1
Thread Starter
Hyperactive Member
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 !!!!!
-
Aug 17th, 2000, 11:01 PM
#2
try adding
Code:
On Error Resume Next
at the beginning of the sub.
-
Aug 17th, 2000, 11:02 PM
#3
I am sure there is a way so you dont get any error, but this is the lazy way out.
-
Aug 18th, 2000, 02:20 AM
#4
transcendental analytic
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.
-
Aug 18th, 2000, 02:44 AM
#5
I recomend the For...Next Loop, those are my favorite 
-
Aug 18th, 2000, 03:03 AM
#6
transcendental analytic
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.
-
Aug 18th, 2000, 03:22 AM
#7
-
Aug 18th, 2000, 08:48 AM
#8
Thread Starter
Hyperactive Member
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
-
Aug 18th, 2000, 11:34 AM
#9
Lively Member
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
-
Aug 18th, 2000, 12:07 PM
#10
transcendental analytic
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|