473,513 Members | 2,368 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Nothing

hi
if i have IsAdmin=True or IsAdmin=False why
(IsAdmin = Nothing) is True???

i have

function test(byval IsAdmin as boolean)
If Not (IsAdmin = Nothing) Then

End if
end if

but it does not work because (IsAdmin = Nothing) is always true. Why?
thank you
Nov 18 '05 #1
7 1438
If you say:

IsAdmin = Nothing

When you look at that variable in the debugger, you will see it is actually
False.

Booleans are value types, and therefore cannot actually be nothing. So
setting one to nothing, just makes it have its default value - which for
booleans is False.

So what happens, is that:

IsAdmin = Nothing
and
IsAdmin = False

Are equivalent in as far as the end result.
"JohnZing" <jo**********@S.P.A.M.yahoo.com> wrote in message
news:Xn**********************************@207.46.2 48.16...
hi
if i have IsAdmin=True or IsAdmin=False why
(IsAdmin = Nothing) is True???

i have

function test(byval IsAdmin as boolean)
If Not (IsAdmin = Nothing) Then

End if
end if

but it does not work because (IsAdmin = Nothing) is always true. Why?
thank you

Nov 18 '05 #2
John
IsAdmin can never be nothing so your check doesn't make much sense.A value
type (such as a boolean) can't be null..so why even bother checking it?
Within .Net, this code is very dangerous as it won't behave the same between
languages. For example, C# won't even compile this code.

Karl

"JohnZing" <jo**********@S.P.A.M.yahoo.com> wrote in message
news:Xn**********************************@207.46.2 48.16...
hi
if i have IsAdmin=True or IsAdmin=False why
(IsAdmin = Nothing) is True???

i have

function test(byval IsAdmin as boolean)
If Not (IsAdmin = Nothing) Then

End if
end if

but it does not work because (IsAdmin = Nothing) is always true. Why?
thank you

Nov 18 '05 #3
VB.Net will compile your
if not (IsAdming = nothing) then

to

if IsAdmin = true Then

also, you shouldn't use an = sign with nothing...but that's back to the
entire reference/value type thing.

Karl
"JohnZing" <jo**********@S.P.A.M.yahoo.com> wrote in message
news:Xn**********************************@207.46.2 48.16...
hi
if i have IsAdmin=True or IsAdmin=False why
(IsAdmin = Nothing) is True???

i have

function test(byval IsAdmin as boolean)
If Not (IsAdmin = Nothing) Then

End if
end if

but it does not work because (IsAdmin = Nothing) is always true. Why?
thank you

Nov 18 '05 #4
"Marina" <so*****@nospam.com> wrote in
news:uO*************@TK2MSFTNGP10.phx.gbl:

So what happens, is that:

IsAdmin = Nothing
and
IsAdmin = False


got it, thank you
but,then, how can i implement this:

function test(byval IsAdmin as boolean)
If IsAdmin = Nothing Then
return "I don't Know"
elseIf IsAdmin=False then
return "Yes"
elseIf IsAdmin=True then
return "No"
End if
end if

sometimes i don't know if IsAdmin is True or False
I thought i could use
label.text=test(nothing)
Nov 18 '05 #5
booleans are always either true or false. So there cannot be an 'i don't
know' option. It's always either yes or no - it's never anythign else. So if
you don't set it to anything, the default is 'no'.

You could try using the SqlBoolean structure, which has a Null static member
you could set it to - which would then denote it is null (though setting it
to Nothing, wouldn't work, as this is a value type as well). However, this
isn't as widely used or intuitive as using a boolean.

"JohnZing" <jo**********@S.P.A.M.yahoo.com> wrote in message
news:Xn**********************************@207.46.2 48.16...
"Marina" <so*****@nospam.com> wrote in
news:uO*************@TK2MSFTNGP10.phx.gbl:

So what happens, is that:

IsAdmin = Nothing
and
IsAdmin = False


got it, thank you
but,then, how can i implement this:

function test(byval IsAdmin as boolean)
If IsAdmin = Nothing Then
return "I don't Know"
elseIf IsAdmin=False then
return "Yes"
elseIf IsAdmin=True then
return "No"
End if
end if

sometimes i don't know if IsAdmin is True or False
I thought i could use
label.text=test(nothing)

Nov 18 '05 #6
John,
A boolean can never be nothing (except in the next version of .net ..to
confuse you ;) )...

You can use an integer when you can have three states, less than zero,
greater than zero or equal to zero which you could cleanly wrap in an
enumeration.

My guess is you are fixated on boolean == null because you are fetching a
bit field from a database that supports null? The enumeration is the best
thing to use:..there's a built-in one in VB already called Tristate never
used it...I'd probably still use my own..but that's just me.

Karl

"JohnZing" <jo**********@S.P.A.M.yahoo.com> wrote in message
news:Xn**********************************@207.46.2 48.16...
"Marina" <so*****@nospam.com> wrote in
news:uO*************@TK2MSFTNGP10.phx.gbl:

So what happens, is that:

IsAdmin = Nothing
and
IsAdmin = False


got it, thank you
but,then, how can i implement this:

function test(byval IsAdmin as boolean)
If IsAdmin = Nothing Then
return "I don't Know"
elseIf IsAdmin=False then
return "Yes"
elseIf IsAdmin=True then
return "No"
End if
end if

sometimes i don't know if IsAdmin is True or False
I thought i could use
label.text=test(nothing)

Nov 18 '05 #7
if you have to support a tri-state like that, then you can't use a boolean.
You can, however do something like"

Public Enum TriState
IsUnknown
IsTrue
IsFalse
End Enum

Public Function Test (isAdmin as Tristate)
if isAdmin=Tristate.IsUnknown
....
End Function

"JohnZing" <jo**********@S.P.A.M.yahoo.com> wrote in message
news:Xn**********************************@207.46.2 48.16...
"Marina" <so*****@nospam.com> wrote in
news:uO*************@TK2MSFTNGP10.phx.gbl:

So what happens, is that:

IsAdmin = Nothing
and
IsAdmin = False


got it, thank you
but,then, how can i implement this:

function test(byval IsAdmin as boolean)
If IsAdmin = Nothing Then
return "I don't Know"
elseIf IsAdmin=False then
return "Yes"
elseIf IsAdmin=True then
return "No"
End if
end if

sometimes i don't know if IsAdmin is True or False
I thought i could use
label.text=test(nothing)

Nov 18 '05 #8

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

Similar topics

96
6153
by: BadPony | last post by:
Anyone using Peoplesoft on a Federated UDB (shared nothing)Environment on Open System Platforms? Preferably AIX, but any war stories would be good. TEA EB-C
24
7635
by: Hardy | last post by:
I'm pretty new in this field. when reading some 70x material, I met with this term but cannot catch its accurate meaning. who can help me? thanks in advance:)~
6
1695
by: Bob Day | last post by:
VS 2003 The documentation says " Nothing keyword represents the default value of any data type" this is simply not true and causing a lot of problems. 1) Consider an SQL table of 3 columns: ...
26
6031
by: Bob Day | last post by:
VS 2003, vb.net, sql native (MSDE)... I have railed against the inconsistency of the Nothing key word. The documentation says is will assign a default value for any datatype...well, not...
4
6516
by: David Schwartz | last post by:
Seems that setting an object = Nothing no longer does anything in .NET. Garbage collection destroys the object eventually. So, does it ever make sense to set an object = Nothing in .NET? Thanks.
5
2057
by: John A Grandy | last post by:
do these mean the same thing ? Dim s As String ..... If s Is Nothing Then ..... If s = Nothing Then .....
8
1617
by: Tiraman | last post by:
Hi , i would like to get some explanation about using the Obj = Nothing . For example , I have a function that hold a local object like in this example public function Test() dim objMyCol...
12
2647
by: Mike Eaton | last post by:
Hi all, What do people regard as the best practice with respect to freeing object references when you're done with them? Some people I've worked with in the past suggested that if you create an...
9
4519
by: Doug Glancy | last post by:
I got the following code from Francesco Balena's site, for disposing of Com objects: Sub SetNothing(Of T)(ByRef obj As T) ' Dispose of the object if possible If obj IsNot Nothing AndAlso...
6
3553
by: DippyDog | last post by:
This is an old old post that I'm referencing regarding what happens when you set an integer variable to Nothing. It gets set to zero, not "Nothing." ...
0
7267
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
7391
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,...
0
7553
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
7542
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...
1
5100
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...
0
4754
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1609
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
809
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
466
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.