vbNullString

  • Thread starter Thread starter Lou
  • Start date Start date
L

Lou

What's the .NET equivalent

Dim strTmp as string
If strTmp=vbNullString

Posted this earlier in the wrong Newsgroup.
 
Lou said:
What's the .NET equivalent?
Dim strTmp as string
If strTmp = vbNullString

As given, I'm not sure you can do this comparison.
Can a String hold a "database-y" null value? (As opposed to a proper
Nothing?)

Well anyway, an Object can, so

Dim o as Object _
= PotentiallyNullValueFromDB()

If o Is System.DBNull.Value Then
. . .

HTH,
Phill W.
 
Lou said:
What's the .NET equivalent

Dim strTmp as string
If strTmp=vbNullString

Posted this earlier in the wrong Newsgroup.

String.Empty
 
Phill said:
As given, I'm not sure you can do this comparison.
Can a String hold a "database-y" null value? (As opposed to a proper
Nothing?)

Well anyway, an Object can, so

Dim o as Object _
= PotentiallyNullValueFromDB()

If o Is System.DBNull.Value Then
. . .

HTH,
Phill W.

vbNullString doesn't represent a database null, it's just an empty string.
 
Göran Andersson said:
String.Empty

Addition:

To check if the string is empty, you should rather check if the length
is zero than to do a string comparison.
 
What's the .NET equivalent

Dim strTmp as string
If strTmp=vbNullString

Posted this earlier in the wrong Newsgroup.

I like using String.IsNullOrEmpty(...) - as it returns a boolean value
indicating if the string is *gasp* null or empty :-).

So your code could be replaced by:

Dim strTmp as String
If String.IsNullOrEmpty(strTmp) Then
' blah blah blah
End If

Thanks,

Seth Rowe
 
String.Empty

Not true. String.Empty equates to "", the zero length string. The MSDN
documentation specifically states that vbNullString is not the same as a
zero-length string.

I think the closest thing would be nothing
 
Göran Andersson said:
vbNullString doesn't represent a database null, it's just an empty string.

It's a string pointer with value 0 in VB6, primarily used when calling Win32
API functions.
 
Rad said:
Not true. String.Empty equates to "", the zero length string. The MSDN
documentation specifically states that vbNullString is not the same as a
zero-length string.

I think the closest thing would be nothing

You are right. There seems to be a lot of confusion out there. I found
advice to use vbNullString instead of "", but then that is not good
advice at all, as they have completely different uses.

I checked the implementation of vbNullString in the
Microsoft.VisualBasic library, and it's a constant string with the value
Nothing, so it's exactly the same as Nothing.
 
Herfried said:
It's a string pointer with value 0 in VB6, primarily used when calling
Win32 API functions.

Yes, you are right.

I searched for how vbNullString was used, and came to the conclusion
that it was an empty string, but most of what I found appearently was
written by people more confused than I was...
 
Herfried,
It's a string pointer with value 0 in VB6, primarily used when calling
Win32 API functions.
Do you mean
"0"
or
a pointer to computer memory address zero
or (as I assume)
a not yet set pointer (represented in VB.Net by the keyword Nothing)

Cor
 
Cor Ligthert [MVP] wrote:
a pointer to computer memory address zero
or (as I assume)
a not yet set pointer (represented in VB.Net by the keyword Nothing)
<snip>

Which, AFAIK, happen to be exactly the same thing.

A pointer to the computer memory address 0 has the value of 0 (a
pointer, I suppose you know, *is* the value it points to), and a "not
yet set pointer" is exactly this, a reference value which was set to 0
-- upon initialization by the VB compiler generated code -- to mean
what other languages call "Null" and we call Nothing.

It became a convention to treat pointers (our "reference values") that
reference the special (and invalid) address 0 as non-initialized,
which is not exactly true: the pointer *was* initialized but to a
value known to be unusable.

Historically VB was one of the languages that always enforced this
notion, initializing the stack area to 0 and thus setting local
variables to a default, known value: 0, false, Nothing, etc. If
someone thinks this is not a big deal, compare it to Delphi, which
doesn't do this and requires you to initialize each and every local
variable before use (which is a major pain, and after you've done that
a zillion times you start looking for the compiler switch that
initializes the variables for you -- but there's none). C and C++ do
the same, but most compilers only warn you of the non-initilizion,
while others don't even bother to, so the programmer can happily use
values set to whatever was in the variable address at run time and
become appalled when things go awry with his/her code...

Uh, I guess I'm heavilly drifting to OT land now...

Regards,

Branco.
 
Back
Top