473,588 Members | 2,574 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 1441
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.co m> wrote in message
news:Xn******** *************** ***********@207 .46.248.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.co m> wrote in message
news:Xn******** *************** ***********@207 .46.248.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.co m> wrote in message
news:Xn******** *************** ***********@207 .46.248.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******** *****@TK2MSFTNG P10.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.co m> wrote in message
news:Xn******** *************** ***********@207 .46.248.16...
"Marina" <so*****@nospam .com> wrote in
news:uO******** *****@TK2MSFTNG P10.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.co m> wrote in message
news:Xn******** *************** ***********@207 .46.248.16...
"Marina" <so*****@nospam .com> wrote in
news:uO******** *****@TK2MSFTNG P10.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=Tristat e.IsUnknown
....
End Function

"JohnZing" <jo**********@S .P.A.M.yahoo.co m> wrote in message
news:Xn******** *************** ***********@207 .46.248.16...
"Marina" <so*****@nospam .com> wrote in
news:uO******** *****@TK2MSFTNG P10.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
6189
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
7650
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
1699
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: Column1 bit no nulls Column2 string no nulls Column3 DateTime no nulls
26
6058
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 exactly. Here are 2 more examples: Example 1) dim x as string = nothing, the value of x is nothing (instead of string.empty). When you add a row to SQL, the column with the value of X will fail in a table that does not allow nulls because Nothing is...
4
6519
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
2060
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
1622
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 as New Collection()
12
2655
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 object with "New" then you should free/set it to nothing when you're finished with it, regardless of whether it's about to go out of scope or not. In a simple example: Private Sub DoSomething() Dim fForm As New frmMain fForm.Show() '... do some...
9
4527
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 TypeOf obj Is IDisposable Then DirectCast(obj, IDisposable).Dispose()
6
3556
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." http://groups.google.com/group/microsoft.public.dotnet.languages.vb/browse_thread/thread/6732ea8e7016bd24/70608745c29d048b?lnk=gst&q=can%27t+set+enum+to+nothing#70608745c29d048b Just to expand the understanding of the problems this behavior can cause, because a typical enumeration (enum) is...
0
7927
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
7857
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8220
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
7981
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6632
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
5723
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5396
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3846
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2367
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 we have to send another system

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.