473,405 Members | 2,334 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,405 software developers and data experts.

vbNullString

Lou
What's the .NET equivalent

Dim strTmp as string
If strTmp=vbNullString

Posted this earlier in the wrong Newsgroup.
Mar 6 '07 #1
13 3687
Lou wrote:
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.
Mar 6 '07 #2
Lou wrote:
What's the .NET equivalent

Dim strTmp as string
If strTmp=vbNullString

Posted this earlier in the wrong Newsgroup.

String.Empty

--
Göran Andersson
_____
http://www.guffa.com
Mar 6 '07 #3
Phill W. wrote:
Lou wrote:
>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.
vbNullString doesn't represent a database null, it's just an empty string.

--
Göran Andersson
_____
http://www.guffa.com
Mar 6 '07 #4
Göran Andersson wrote:
Lou wrote:
>What's the .NET equivalent

Dim strTmp as string
If strTmp=vbNullString

Posted this earlier in the wrong Newsgroup.

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.

--
Göran Andersson
_____
http://www.guffa.com
Mar 6 '07 #5
On Mar 6, 12:51 pm, "Lou" <lou.gar...@comcast.netwrote:
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

Mar 6 '07 #6
On Tue, 06 Mar 2007 21:20:01 +0100, Göran Andersson wrote:
Lou wrote:
>What's the .NET equivalent

Dim strTmp as string
If strTmp=vbNullString

Posted this earlier in the wrong Newsgroup.

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
--
Bits.Bytes
http://bytes.thinkersroom.com
Mar 6 '07 #7
"Göran Andersson" <gu***@guffa.comschrieb:
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.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Mar 6 '07 #8
Rad [Visual C# MVP] wrote:
On Tue, 06 Mar 2007 21:20:01 +0100, Göran Andersson wrote:
>Lou wrote:
>>What's the .NET equivalent

Dim strTmp as string
If strTmp=vbNullString

Posted this earlier in the wrong Newsgroup.
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
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.

--
Göran Andersson
_____
http://www.guffa.com
Mar 7 '07 #9
Herfried K. Wagner [MVP] wrote:
"Göran Andersson" <gu***@guffa.comschrieb:
>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.
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...

--
Göran Andersson
_____
http://www.guffa.com
Mar 7 '07 #10
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
Mar 9 '07 #11
Cor Ligthert [MVP] wrote:
<snip>
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.

Mar 9 '07 #12
>
Uh, I guess I'm heavilly drifting to OT land now...
I don't think so, in my opinion does your text add quiet a bit to the
thread.

Cor
Mar 9 '07 #13
"Cor Ligthert [MVP]" <no************@planet.nlschrieb:
>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
'(LP<...>STR)0' in C, so a pointer to a memory address.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Mar 9 '07 #14

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

Similar topics

43
by: ZillionDollarSadist | last post by:
Hello, I'm working at a simple Access '97 + VB4 application, and I ran into a terrible problem: something I never modified now gives me a totally unwanted "Invalid use of null" error. It happens...
3
by: Larry | last post by:
Hi all, I am coming over from VB 6, learning VB.NET. I have read and have in front of me, the language reference from the msdn, on; Behavior of Null has changed, Isdbnull function and...
6
by: Tark Siala | last post by:
hi lasr years i use vb6 to make my Application Database with ADO, this days i use VB.NET to working with Database. to know if Field contain null i use: if recordset.field("data").value =...
11
by: Lou | last post by:
What's the .NET equivalent Dim strTmp as string If strTmp=vbNullString
10
by: Dollarstar | last post by:
I've been looking around and I got some info but not to what I really need. I have a Database with several values, one being a date. When four days have passed from this date I get a warning...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.