Computing.Net > Forums > Programming > Vb.net

Computing.Net: Over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to sign up now, it's free!

Vb.net

Reply to Message Icon

Original Message
Name: Val
Date: October 23, 2002 at 10:17:57 Pacific
Subject: Vb.net
OS: windows 2000
CPU/Ram: don't know
Comment:

Does anybody know how to check in VB.NET if array is empty?
Thank you



Report Offensive Message For Removal


Response Number 1
Name: Jeff J
Date: October 23, 2002 at 12:09:49 Pacific
Reply: (edit)

By empty, I assume you are refering to a VB5/6 Variant type, which could "hold" an array. If an array (or anything else) was not assigned to a Variant, one could use the IsEmpty() function on the Variant, to see if it refered to an array. Arrays themselves cannot be checked for emptiness, since if they exist, they never are.

VB.Net does still provide the Object type, which is an enhanced version of the VB5/6 Object type. They completely replace the Variant type, and can be checked as before by seeing if they refer to Nothing (null pointer in C/C++ terms):

Dim oVar As Object
' do stuff with object,
' such as Set oVar = MyArray

If oVar Is Nothing Then '...

FWIW, it's probably best that the concept of being "empty" has been dropped, since it is misleading and not used by most other languages anyway. As it is, the keyword "Nothing" in VB becomes the keyword null/NULL in most other popular languages.

Cheers


Report Offensive Follow Up For Removal







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home








Do you have your own blog?

Yes
No
I did before
I will soon


View Results

Poll Finishes In 4 Days.
Discuss in The Lounge
Poll History




Data Recovery Software