473,467 Members | 2,383 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

No boolean object in VB.NET? How to check if a boolean has been explicitely defined then?


In java for instance there's a way to use booleans as objects and not as
value types.
I would like to do the same in VB.NET so that I can check if the boolean has
been explicitely defined (is not Nothing).
But Boolean is a Structure in VB.NET (defined to False by default) and not
an Object so I'm afraid there's no way to do what I want without any
workaround.
Can you confirm that there's no object version of Boolean in VB.NET?
Thanks

Henri

Nov 21 '05 #1
10 13788
"Henri" <hm********@hotmail.com> wrote in
news:un**************@TK2MSFTNGP12.phx.gbl:

In java for instance there's a way to use booleans as objects and not
as value types.
I would like to do the same in VB.NET so that I can check if the
boolean has been explicitely defined (is not Nothing).
But Boolean is a Structure in VB.NET (defined to False by default) and
not an Object so I'm afraid there's no way to do what I want without
any workaround.
Can you confirm that there's no object version of Boolean in VB.NET?

Nope, I don't believe there is a Boolean object.

And there should be a way for you to do what you want to do because
millions of .NET developers don't use a Boolean object ; )

--
Lucas Tam (RE********@rogers.com)
Please delete "REMOVE" from the e-mail address when replying.
http://members.ebay.com/aboutme/coolspot18/
Nov 21 '05 #2
Couldn't you just make a class that contains a public property and has a
private Boolean field? The value of the private Boolean field determines
the value of the public property? If the private field value hasn't been
set, then the public property value stays at its default (which you set to
Nothing in the class constructor).


"Henri" <hm********@hotmail.com> wrote in message
news:un****************@TK2MSFTNGP12.phx.gbl...

In java for instance there's a way to use booleans as objects and not as
value types.
I would like to do the same in VB.NET so that I can check if the boolean
has
been explicitely defined (is not Nothing).
But Boolean is a Structure in VB.NET (defined to False by default) and not
an Object so I'm afraid there's no way to do what I want without any
workaround.
Can you confirm that there's no object version of Boolean in VB.NET?
Thanks

Henri

Nov 21 '05 #3

"Henri" <hm********@hotmail.com> wrote in message
news:un****************@TK2MSFTNGP12.phx.gbl...
:
: In java for instance there's a way to use booleans as objects and not
: as value types.
: I would like to do the same in VB.NET so that I can check if the
: boolean has been explicitely defined (is not Nothing).
: But Boolean is a Structure in VB.NET (defined to False by default) and
: not an Object so I'm afraid there's no way to do what I want without
: any workaround.
: Can you confirm that there's no object version of Boolean in VB.NET?
: Thanks
:
: Henri
Perhaps you could 'box' the boolean type along these lines:

Dim BooleanObj As Object = New Boolean
For Example:

---------------------------------------------------
Option Strict
Imports System

Public Class [class]
Public Shared Sub Main

'Outputs "True"
Dim BooleanObj As Object
Console.Writeline(BooleanObj Is Nothing)

'Outputs "False"
BooleanObj = New Boolean
Console.Writeline(BooleanObj Is Nothing)

'Outputs "False"
Console.WriteLine(BooleanObj)

'Outputs "True"
BooleanObj = True
Console.WriteLine(BooleanObj)

End SUb
End Class
---------------------------------------------------
Or if you prefer, you can write your own class:
---------------------------------------------------
Public Class BooleanObj
Private b As Boolean

Public Sub New
End Sub

Public Sub New(Value As Boolean)
b = Value
End Sub

Public Property Value() As Boolean
Get
Return b
End Get
Set
b = value
End Set
End Property

Public Overrides Function ToString() As String
Return b.toString
End Function

Public Overrides Overloads Function Equals(obj As Object) As Boolean

If obj Is Nothing Then
Return False
End If

If Not Me.GetType() Is obj.GetType() Then
Return False
End If

Dim o As BooleanObj = CType(obj, BooleanObj)
If b <> o.b Then
Return False
End IF

Return True

End Function

End Class
---------------------------------------------------
Ralf
Nov 21 '05 #4
well i guess this is a easy way
Dim objBool As Object = Nothing

objBool = True ' or objBool = false

If IsNothing(objBool) Then

MsgBox("i am not set")

Else

MsgBox(CType(objBool, Boolean))

End If

however there are so manny roads to Rome :-) some may go pass Paris or
Madrid

regards

Michel Posseth [MCP]

"Henri" <hm********@hotmail.com> wrote in message
news:un****************@TK2MSFTNGP12.phx.gbl...

In java for instance there's a way to use booleans as objects and not as
value types.
I would like to do the same in VB.NET so that I can check if the boolean
has
been explicitely defined (is not Nothing).
But Boolean is a Structure in VB.NET (defined to False by default) and not
an Object so I'm afraid there's no way to do what I want without any
workaround.
Can you confirm that there's no object version of Boolean in VB.NET?
Thanks

Henri

Nov 21 '05 #5
"Henri" <hm********@hotmail.com> schrieb:
In java for instance there's a way to use booleans as objects and not as
value types.
I would like to do the same in VB.NET so that I can check if the boolean
has
been explicitely defined (is not Nothing).
But Boolean is a Structure in VB.NET (defined to False by default) and not
an Object so I'm afraid there's no way to do what I want without any
workaround.
Can you confirm that there's no object version of Boolean in VB.NET?


You may want to use a class that wraps a boolean value instead of the
standard 'Boolean' type:

\\\
Public Class NullableBoolean
Public Sub New()
'
End Sub

Public Sub New(ByVal Value As Boolean)
Me.Value = Value
End Sub

Public Value As Boolean
End Class
///

- or -

\\\
Public Structure NullableBoolean
Public Value As Boolean
Public IsNull As Boolean
End Structure
///

The .NET Framework contains an 'SqlBoolean' structure which is nullable.

In VB 2005 you can use generics ('Nullable') to create a nullable boolean
type ('Nullable(Of Boolean)'.

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

Nov 21 '05 #6
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:eV**************@TK2MSFTNGP09.phx.gbl...
In VB 2005 you can use generics ('Nullable') to create a nullable boolean
type ('Nullable(Of Boolean)'.


I tried that with VB 2005 but I didn't get the expected results. What am I
missing?

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click

Dim x As Nullable(Of Boolean)

MsgBox(String.Format("IsNothing( x ) = {0:G}", IsNothing(x)))

End Sub

IsNothing(x) is returning False, not the True that I expected. I also tried
declaring x with:

Dim x As Nullable(Of Boolean) = Nothing

but I got the same result (False).



Nov 21 '05 #7
"Alex" <pl******@no.messages> schrieb:
In VB 2005 you can use generics ('Nullable') to create a nullable boolean
type ('Nullable(Of Boolean)'.


I tried that with VB 2005 but I didn't get the expected results. What am
I
missing?

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click

Dim x As Nullable(Of Boolean)

MsgBox(String.Format("IsNothing( x ) = {0:G}", IsNothing(x)))

End Sub

IsNothing(x) is returning False, not the True that I expected. I also
tried
declaring x with:

Dim x As Nullable(Of Boolean) = Nothing

but I got the same result (False).


You'll have to check the object's 'HasValue' property in order to determine
whether or not a value has been assigned. VB 2005 won't have built-in
support for nullable types.

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

Nov 21 '05 #8
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:O%***************@TK2MSFTNGP15.phx.gbl...
You'll have to check the object's 'HasValue' property in order to determine
whether or not a value has been assigned.
Thanks.
VB 2005 won't have built-in support for nullable types.


I am confused by that statement. How's that different than with C#? What kind
of support will C# get that VB won't?

Nov 21 '05 #9
"Alex" <pl******@no.messages> schrieb:
You'll have to check the object's 'HasValue' property in order to
determine
whether or not a value has been assigned.

VB 2005 won't have built-in support for nullable types.


I am confused by that statement. How's that different than with C#? What
kind
of support will C# get that VB won't?


C# will support some additional type keywords and operators for dealing with
nullable types:

<URL:http://msdn2.microsoft.com/library/2cf62fcy(en-us,vs.80).aspx>

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

Nov 21 '05 #10

Thank you so much for your help to all of you!!!
:-)

Henri
"Henri" <hm********@hotmail.com> a écrit dans le message de
news:un****************@TK2MSFTNGP12.phx.gbl...


In java for instance there's a way to use booleans as objects and not as
value types.
I would like to do the same in VB.NET so that I can check if the boolean has been explicitely defined (is not Nothing).
But Boolean is a Structure in VB.NET (defined to False by default) and not
an Object so I'm afraid there's no way to do what I want without any
workaround.
Can you confirm that there's no object version of Boolean in VB.NET?
Thanks

Henri


Nov 21 '05 #11

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

Similar topics

2
by: Kai Wu | last post by:
Hello, Sometimes it is desired to assert an object as boolean value, e.g. class A{ }; ....... A a; while(a=next()){
26
by: JGH | last post by:
How can I check if a key is defined in an associative array? var users = new array(); users = "Joe Blow"; users = "John Doe"; users = "Jane Doe"; function isUser (userID) { if (?????)
5
by: DJTB | last post by:
Dear Group, I'd like to check if a value is defined in an enum. Example: ------------------------------------------------------ typedef enum { A_VALUE = 1,
7
by: Wessel Troost | last post by:
Hi Group, How can you check if a variable is defined in C#? For example, "string s;" would declare an undefined variable. But how can I check in an "if" statement wether it's defined or not?...
5
by: Rahul T. | last post by:
Hello All, I am trying to create a web service. This web service for now, has to use couple of exisiting COM components. I have added them in my .NET project as COM interop. Most of the time...
1
by: Marco Castro | last post by:
I'm getting the error "COM object that has been separated from its underlying RCW can not be used." whenever I run one of my functions too much. It didn't use to this until I moved part of it into...
2
by: Steve | last post by:
(I posted this in the ADO.NET NG, but didn't get any responses) I've started getting this exception since installing vs2005 "COM object that has been separated from its underlying RCW cannot be...
4
by: Michael Maes | last post by:
Hi, On closing our App, we get following 'InvalidComObjectException': "COM object that has been separated from its underlying RCW cannot be used" The App has been upgraded from .Net1.1 to...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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...
1
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,...
1
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
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...

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.