473,387 Members | 1,520 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Help - Array = Nothing - How do I catch

I have a function that returns an array of string values, occasionally
the returned array value is 'Nothing'
I need to check if the value is nothing before moving on - how can I do
this - none of the options i've looked at seems to fit? (vb2005)

Thanks

Pete

Jan 21 '07 #1
12 10019
Ummmmm ... How about:

variable Is Nothing
"xla76" <pe*********@gmail.comwrote in message
news:11**********************@38g2000cwa.googlegro ups.com...
>I have a function that returns an array of string values, occasionally
the returned array value is 'Nothing'
I need to check if the value is nothing before moving on - how can I do
this - none of the options i've looked at seems to fit? (vb2005)

Thanks

Pete

Jan 21 '07 #2
Doh!

Thanks
Stephany Young wrote:
Ummmmm ... How about:

variable Is Nothing
Jan 21 '07 #3
"xla76" <pe*********@gmail.comschrieb:
>I have a function that returns an array of string values, occasionally
the returned array value is 'Nothing'
\\\
If s(n) IsNot Nothing Then
...
End If
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
Jan 21 '07 #4
"xla76" <pe*********@gmail.comha scritto nel messaggio
news:11**********************@s34g2000cwa.googlegr oups.com...
Doh!

Thanks
Stephany Young wrote:
>Ummmmm ... How about:

variable Is Nothing
Nothe that is a bad practice returning nothing for an array or a collection.
If the code is your you'd better return an empty array or a collection with
0 elements.

--
www.neodatatype.net
Jan 21 '07 #5
"Fabio" <zn*******@virgilio.itschrieb
>
Nothe that is a bad practice returning nothing for an array or a
collection. If the code is your you'd better return an empty array
or a collection with 0 elements.

If there is nothing to return why not return nothing? Sometimes Nothing
expresses something different from an empty array. I think it depends on the
purpose of the function whether it makes sense to return Nothing.
Armin

Jan 21 '07 #6
Armin,

I was in doubt if I would write something about this. Now you do it, it is
easy to write that I agree with you. Just to show my opinion in this. In
this case was showing nothing bad.

Cor

"Armin Zingler" <az*******@freenet.deschreef in bericht
news:%2****************@TK2MSFTNGP05.phx.gbl...
"Fabio" <zn*******@virgilio.itschrieb
>>
Nothe that is a bad practice returning nothing for an array or a
collection. If the code is your you'd better return an empty array
or a collection with 0 elements.


If there is nothing to return why not return nothing? Sometimes Nothing
expresses something different from an empty array. I think it depends on
the
purpose of the function whether it makes sense to return Nothing.
Armin

Jan 22 '07 #7
Dim Arr As Array

If Arr.GetLength= 0 then
The Grand Master
xla76 wrote:
I have a function that returns an array of string values, occasionally
the returned array value is 'Nothing'
I need to check if the value is nothing before moving on - how can I do
this - none of the options i've looked at seems to fit? (vb2005)

Thanks

Pete
Jan 22 '07 #8
"Armin Zingler" <az*******@freenet.deha scritto nel messaggio
news:%2****************@TK2MSFTNGP05.phx.gbl...

>Nothe that is a bad practice returning nothing for an array or a
collection. If the code is your you'd better return an empty array
or a collection with 0 elements.


If there is nothing to return why not return nothing? Sometimes Nothing
expresses something different from an empty array. I think it depends on
the
purpose of the function whether it makes sense to return Nothing.
Simply because it is ambiguos for the developer that will use that code.
He won't know if the function will return something or not and force him to
overkill code to test useless condition such as

If Not array Is Nothing Then
If array.Lenght 0 Then
Else
' error
Endif
Else
' error
Endif

resulting in less readable code, less performances and so on, and if Him
forget/don't know that the array can be nothing the app will crash.

This is the same reason for that someone suggest to not return nothing for a
derived class in a factory pattern but an istance of MyInvalidClass.

But everyone can choose its way to be "not CLS compliant" :)
Jan 22 '07 #9
"Fabio Z" <zn*******@virgilio.itschrieb
"Armin Zingler" <az*******@freenet.deha scritto nel messaggio
news:%2****************@TK2MSFTNGP05.phx.gbl...

Nothe that is a bad practice returning nothing for an array or a
collection. If the code is your you'd better return an empty
array or a collection with 0 elements.

If there is nothing to return why not return nothing? Sometimes
Nothing expresses something different from an empty array. I think
it depends on the
purpose of the function whether it makes sense to return Nothing.

Simply because it is ambiguos for the developer that will use that
code. He won't know if the function will return something or not
If he doesn't know he should read the function's documentation.

"If the file is not found, the return value is Nothing. Otherwise it returns
an array containing one item per entry within the file. There might be zero
items in the file." (just an example)

BTW, zero <DBNull.Value.
and
force him to overkill code to test useless condition such as

If Not array Is Nothing Then
If array.Lenght 0 Then
Else
' error
Endif
Else
' error
Endif

resulting in less readable code, less performances and so on,
I think it is not less readable. The code handles all possible situations.
and if
Him forget/don't know that the array can be nothing the app will
crash.
see 1st paragraph
This is the same reason for that someone suggest to not return
nothing for a derived class in a factory pattern but an istance of
MyInvalidClass.

But everyone can choose its way to be "not CLS compliant" :)
Not a CLS issue, I think.
Armin

Jan 22 '07 #10
"Armin Zingler" <az*******@freenet.deha scritto nel messaggio
If he doesn't know he should read the function's documentation.
If you wrote it.

"If the file is not found, the return value is Nothing.
Boolean?

Otherwise it returns an array containing one item per entry within the
file. There might be zero items in the file." (just an example)
???
I don't understand the example.

BTW, zero <DBNull.Value.
???
from where DBNull.Value comes now?
DBNull.Value is a special class (As I sayd in previous post) used instead of
Nothing to indicate a non valid value.
>
Not a CLS issue, I think.
Yes, just a common sense issue.
I would say "everyone can choose its way to write bad code".
Jan 22 '07 #11
"Fabio Z" <zn*******@virgilio.itschrieb
"Armin Zingler" <az*******@freenet.deha scritto nel messaggio
If he doesn't know he should read the function's documentation.

If you wrote it.
And if you use it. If you don't know what you use, you shouldn't.
"If the file is not found, the return value is Nothing.

Boolean?
"As String()"?

I think I see what you mean but this would require another argument. Both is
valid.
Otherwise it returns an array containing one item per entry within
the file. There might be zero items in the file." (just an
example)

???
I don't understand the example.
It shows that Nothing and an empty array is not the same. Nothing can
express something different than an empty array. The documentation clearly
states when is returned what.
BTW, zero <DBNull.Value.

???
from where DBNull.Value comes now?
DBNull.Value is a special class (As I sayd in previous post) used
instead of Nothing to indicate a non valid value.
I wanted to show that zero is not the same as DBNull.Value just like Nothing
is not the same as an empty array.

Not a CLS issue, I think.

Yes, just a common sense issue.
I would say "everyone can choose its way to write bad code".
Umm.... yes.
Armin

Jan 22 '07 #12
"Armin Zingler" <az*******@freenet.deha scritto nel messaggio
news:eC*************@TK2MSFTNGP06.phx.gbl...

If he doesn't know he should read the function's documentation.

If you wrote it.

And if you use it. If you don't know what you use, you shouldn't.
Ok, you're right.
"If you don't know what you use, you shouldn't"


Jan 22 '07 #13

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: MattP | last post by:
Ok, with the help of some examples found on the web and some minor modifications on our own, we have a simple and working encrypt and decrypt solution. It runs as a service, watches for files with...
6
by: James Radke | last post by:
Hello, I have a multithreaded windows NT service application (vb.net 2003) that I am working on (my first one), which reads a message queue and creates multiple threads to perform the processing...
5
by: SStory | last post by:
Hi all, I really needed to get the icons associated with each file that I want to show in a listview. I used the follow modified code sniplets found on the internet. I have left in...
3
by: Keith Mills | last post by:
Hello, please find attached a basic outline of what I am attempting to accomplish... basically I want to create a number of THREADS (which I can do fine), but I then need a method for them to be...
2
by: Allen | last post by:
Hey all, I have a question for you all. I'm learning vb.net and need some help. I have two classes one named Customers and one named CustomersDA. I have to go though Customer for everything. I have...
16
by: Allen | last post by:
I have a class that returns an arraylist. How do I fill a list box from what is returned? It returns customers which is a arraylist but I cant seem to get the stuff to fill a list box. I just...
2
by: Bonzol | last post by:
vb.net 2003 Windows application We have a Client/Server system set up by communicating through a TCPClient object. The server loops continuously using a tcplistener device and each time a client...
0
by: gunimpi | last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431 ******************************************************** VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help wanted...
0
by: shahiz | last post by:
This the error i get when i try to run my program Error: Unable to realize com.sun.media.amovie.AMController@18b81e3 Basically i have a mediapanel class that initialize and play the media as...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.