vbNullString

  • Thread starter Thread starter Lou
  • Start date Start date
String.Empty <=> "" (or any uninitialized As String variable or parameter in
VB6)
null <=> vbNullString (very rare, typically only use in native interops)
 
I don't understand what <=> means. Does that mean less than, equal to, and
greater than?

I assumed the OP was asking about converting vbNullString from VB6 to
VB.Net.

Null does not equal vbNullString in VB6. They are two completely different
things.

String.Empty is the replacement for vbNullString.

String.Empty = ""
Nothing = ""
String.Empty = Nothing --> True

Note that you can not do this:

Dim str As String
Debug.Print(str)

You *must* assign a value to str before you can display or print it, even
if it's String.Empty. For this reason, many people initialize their strings
like this:

Dim str As String = String.Empty

Robin S.
-----------------------------
 
I don't understand what <=> means. Does that mean less than, equal to, and
greater than?

I assumed the OP was asking about converting vbNullString from VB6 to
VB.Net.

Null does not equal vbNullString in VB6. They are two completely different
things.

String.Empty is the replacement for vbNullString.

String.Empty = ""
Nothing = ""
String.Empty = Nothing --> True

Note that you can not do this:

Dim str As String
Debug.Print(str)

You *must* assign a value to str before you can display or print it, even
if it's String.Empty. For this reason, many people initialize their strings
like this:

Dim str As String = String.Empty

Robin S.

Hey Robin,

vbNullString is not equal to String.Empty. 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
 
Rad said:
Hey Robin,

vbNullString is not equal to String.Empty. 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

So here's my algebraic thinking.

In vb6: ?vbNullString = "" --> true
In VB.Net: ?String.Empty = "" --> true
(?Nothing = "" --> true, so this is weird)

Algebraically speaking, if (a = b) and (b = c) then (a = c).

Therefore, if (vbNullString = '") and ("" = String.Empty),
then (vbNullString = String.Empty).

That's my theory!

Unless algebra doesn't hold true for .Net programming, in which I'm
screwed.

Robin S.
 
Being a VB developer (since vb3), I hereby confirm that vbNullString is
equivalent to Nothing. And a "nulled" variable is equivalent to
String.Empty

Here's an ASP.NET scenario:

Page 1 submits FormField1 to Page 2. FormField1 is an empty textbox. Page
1 posts to Page 2.
Page 2 instantiates a variable, varField1.
varField1 = Request.Form("FormField1") results in varField1 = String.Empty
BUT
varField1 = Request.Form("FormField2") .. which does not exist... then
varField1 = Nothing (not an empty string, but just no value assigned).

I have run across this conundrum several times in my career, and it always
amazes me how C-based developers don't see the difference =o)

- nasser
 
"RobinS" posted...
: So here's my algebraic thinking.
:
: In vb6: ?vbNullString = "" --> true
: In VB.Net: ?String.Empty = "" --> true
: (?Nothing = "" --> true, so this is weird)
:
: Algebraically speaking, if (a = b) and (b = c) then (a = c).
:
: [...]
:
: Unless algebra doesn't hold true for .Net programming, in which
: I'm screwed.

Golly Gee Batman!

Not True <> False!
Not False <> True!

If (a = True), (b = False), (c = True) Then
a + b = c and
b + c = c
b + c = a

Algebra does not apply! What shall we call the Screwy one,
Batman?!?

Screwballs, Robin!
 
Jim Carlock said:
"RobinS" posted...
: So here's my algebraic thinking.
:
: In vb6: ?vbNullString = "" --> true
: In VB.Net: ?String.Empty = "" --> true
: (?Nothing = "" --> true, so this is weird)
:
: Algebraically speaking, if (a = b) and (b = c) then (a = c).
:
: [...]
:
: Unless algebra doesn't hold true for .Net programming, in which
: I'm screwed.

Golly Gee Batman!

Not True <> False!
Not False <> True!

If (a = True), (b = False), (c = True) Then
a + b = c and
b + c = c
b + c = a

Algebra does not apply! What shall we call the Screwy one,
Batman?!?

Screwballs, Robin!
 
So here's my algebraic thinking.

In vb6: ?vbNullString = "" --> true
In VB.Net: ?String.Empty = "" --> true
(?Nothing = "" --> true, so this is weird)

Algebraically speaking, if (a = b) and (b = c) then (a = c).

Therefore, if (vbNullString = '") and ("" = String.Empty),
then (vbNullString = String.Empty).

That's my theory!

Unless algebra doesn't hold true for .Net programming, in which I'm
screwed.

Robin S.

Looks like MSDN is a bit of a goof. Much as it says string.Empty <> "" A
quick console application shows otherwise

Console.WriteLine(String.Empty="") -> True
Console.WriteLine(string.Empty=nothing) -> True
 
Rad said:
Looks like MSDN is a bit of a goof. Much as it says string.Empty <> "" A
quick console application shows otherwise

Console.WriteLine(String.Empty="") -> True
Console.WriteLine(string.Empty=nothing) -> True

Algebra rules!

Robin S.
 
Back
Top