|
-
Oct 12th, 2000, 09:05 AM
#1
Thread Starter
New Member
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
-
Oct 12th, 2000, 09:15 AM
#2
Frenzied Member
Code:
If UBound(MyArray) = 0 Then MsgBox "EMPTY!"
Jop - validweb.nl
Alcohol doesn't solve any problems, but then again, neither does milk.
-
Oct 12th, 2000, 09:16 AM
#3
Addicted Member
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
-
Oct 12th, 2000, 09:39 AM
#4
Frenzied Member
We have a different defenition of empty
Jop - validweb.nl
Alcohol doesn't solve any problems, but then again, neither does milk.
-
Oct 12th, 2000, 10:05 AM
#5
Addicted Member
I guess we do. My Bad vIsEmptyTF = true
I like your way better anyway!
Joe
-
Oct 12th, 2000, 03:00 PM
#6
If you are dealing with numeric expressions, use 0 instead of "".
Code:
If aMyArray(i) <> 0 Then
-
Oct 12th, 2000, 03:13 PM
#7
transcendental analytic
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.
-
Oct 12th, 2000, 11:07 PM
#8
Addicted Member
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
-
Jan 12th, 2001, 09:18 AM
#9
Lively Member
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
-
Jan 12th, 2001, 11:41 AM
#10
transcendental analytic
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.
-
Jan 12th, 2001, 11:50 AM
#11
Frenzied Member
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.
-
Jan 12th, 2001, 11:55 AM
#12
transcendental analytic
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.
-
Jan 12th, 2001, 11:56 AM
#13
Frenzied Member
I'll never be better than Kedaman
Jop - validweb.nl
Alcohol doesn't solve any problems, but then again, neither does milk.
-
Jan 12th, 2001, 11:58 AM
#14
_______
<?>
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
-
Jan 12th, 2001, 12:04 PM
#15
Frenzied Member
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.
-
Jan 12th, 2001, 12:17 PM
#16
_______
<?>
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
-
Jan 12th, 2001, 12:23 PM
#17
Frenzied Member
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.
-
Jan 12th, 2001, 12:27 PM
#18
_______
<?>
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
-
Jan 12th, 2001, 12:28 PM
#19
transcendental analytic
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.
-
Jan 12th, 2001, 12:45 PM
#20
_______
"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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|