Function return values

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

It would be really nice if there was an option that warned the developer that calls to functions did not handle the returned value, or alternatively threw a compilation error.
I have been caught so many times by witing something like
Split(myString,",")
instead of
MyArray = Split(myString,",")
(or maybe it is there and I havent found it?)

guy
 
It would be really nice if there was an option that warned the developer that calls to functions did not handle the returned value, or alternatively threw a compilation error.
I have been caught so many times by witing something like
Split(myString,",")
instead of
MyArray = Split(myString,",")
(or maybe it is there and I havent found it?)

guy

The simple explanation is that it's not an error. Although a warning might
be appropriate.

For the split function, you don't necessarily need to assign the return to
a variable. While I'm not saying that you should use it in this manner,
you can use it like this:

'Display the 3rd token in the string
MsgBox(Split(myString,",")(2))

or

'Assigns the 5th token of the string to the variable MyToken
Dim MyToken As String = Split(myString,",")(4)


--
Chris

dunawayc[AT]sbcglobal_lunchmeat_[DOT]net

To send me an E-mail, remove the "[", "]", underscores ,lunchmeat, and
replace certain words in my E-Mail address.
 
guywrote:
It would be really nice if there was an option that warned the
developer that calls to functions did not handle the returned value,
or alternatively threw a compilation error.
I have been caught so many times by witing something like
Split(myString,",")
instead of
MyArray = Split(myString,",")
(or maybe it is there and I havent found it?)

guy

I always end up doing "SomeString.Replace(...." instead of "SomeString
= SomeString.Replace(...".

I think a compiler warning for these is entirely reasonable. If
Microsoft hears about it, I'm sure they would agree. (Is it possible
to get feedback to Microsoft on this stuff? I've tried submitting
bugs, but there was no straightforward way to do this, so maybe
suggestions are out of the question).
 
Jimi,
thanks for your support:-)
guy

Jimi said:
It would be really nice if there was an option that warned the
developer that calls to functions did not handle the returned value,
or alternatively threw a compilation error.

I always end up doing "SomeString.Replace(...." instead of "SomeString
= SomeString.Replace(...".

I think a compiler warning for these is entirely reasonable. If
Microsoft hears about it, I'm sure they would agree. (Is it possible
to get feedback to Microsoft on this stuff? I've tried submitting
bugs, but there was no straightforward way to do this, so maybe
suggestions are out of the question).
 
Not a long time ago, I recommended here to invent an Attribute
[MustUseReturnValue()] or something similar.
The compiler should give a warning if you do not use the return value of a
method marked with this Attribute.

--
cody

Freeware Tools, Games and Humour
http://www.deutronium.de.vu || http://www.deutronium.tk
guy said:
It would be really nice if there was an option that warned the developer
that calls to functions did not handle the returned value, or alternatively
threw a compilation error.
 
Back
Top