473,500 Members | 1,605 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Bad Boolean

I tried to use either a CheckBox or Radio Button to set a
Boolean variable but I get Cast error message with either
when I try to use the Boolean in an IF statement.

How can I use the Check box control to set the Boolean
and not get a cast error later in the code with I try to
use the Boolean in an If statement?

Thanks!

Bob
----------------------------

blnGetAllFolders = RadioButton1
blnGetAllFolders = CheckBox1
....
If blnGetAllFolders Then
....
-----------------------------
Resulting Error message:

An unhandled exception of
type 'System.InvalidCastException' occurred in
microsoft.visualbasic.dll

Additional information: Operator is not valid for Boolean
and RadioButton (or CheckBox).
Nov 21 '05 #1
2 1749
Hi,

try:

blnGetAllFolders = RadioButton1.Checked
blnGetAllFolders = CheckBox1.Checked

hth

Peter
"BobAchgill" <an*******@discussions.microsoft.com> schreef in bericht
news:11****************************@phx.gbl...
I tried to use either a CheckBox or Radio Button to set a
Boolean variable but I get Cast error message with either
when I try to use the Boolean in an IF statement.

How can I use the Check box control to set the Boolean
and not get a cast error later in the code with I try to
use the Boolean in an If statement?

Thanks!

Bob
----------------------------

blnGetAllFolders = RadioButton1
blnGetAllFolders = CheckBox1
...
If blnGetAllFolders Then
...
-----------------------------
Resulting Error message:

An unhandled exception of
type 'System.InvalidCastException' occurred in
microsoft.visualbasic.dll

Additional information: Operator is not valid for Boolean
and RadioButton (or CheckBox).

Nov 21 '05 #2
"BobAchgill" <an*******@discussions.microsoft.com> wrote in message
news:11****************************@phx.gbl...
I tried to use either a CheckBox or Radio Button to set a
Boolean variable but I get Cast error message with either
when I try to use the Boolean in an IF statement.
A Boolean variable can only hold True or False, which can /always/
be used in an IF.
blnGetAllFolders = RadioButton1
RadioButton1 is a variable containing an object reference (to the
RadioButton control). You are assigning this object reference
into the variable blnGetAllFolders.

1) Turn on Option Strict. It really, /really/, *really* is worth it.
(If you're not running with Option Explicit on, I give up!)

2) VB.Net doesn't use default properties like VB "Proper" did.
So,when you now talk about RadioButton1, you really /are/
talking about the RadioButton /itself/, not the Checked property.

In fact, VB did actually tell you this in the Exception:
Additional information: Operator is not valid for Boolean
and RadioButton (or CheckBox).


blnGetAllFolders = RadioButton1.Checked

will work rather better.

HTH,
Phill W.
Nov 21 '05 #3

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

Similar topics

14
2481
by: greg | last post by:
Discussion is invited on the following proto-PEP. ------------------------------------------------------------- PEP ??? - Overloadable Boolean Operators...
2
6880
by: Eyal | last post by:
Hey, I would appriciate if anyone can help on this one: I have a java object/inteface having a method with a boolean parameter. As I'm trying to call this method from a javascript it fails on...
8
3241
by: Metro Sauper | last post by:
Why is the default text representation for booleans in C# 'True' and 'False' whereas in xml it is 'true' and 'false'? It seems like it would make sense to have them both the same. Metro T....
2
2333
by: Raj | last post by:
Hi, When we are sorting the DataGrid Boolean column the grid is becoming redcross. I have my own PPMIPDataGridBoolColumn class inherited from System.Windows.Forms.DataGridBoolColumn. In this...
10
13794
by: Henri | last post by:
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...
0
1368
by: ECathell | last post by:
Ok this may be a silly question...but here goes... I need to extend the boolean type. the reason for this is I have a base collection that has boolean properties. Then my inherited class has...
5
3416
by: Rob Meade | last post by:
Hi all, Quick question if I may... I have a function which depending on whether it was succesful to do something or not returns True or False as a boolean. I have another function which...
10
16374
by: dba123 | last post by:
Why am I getting this error for Budget? Error: An exception of type 'System.FormatException' occurred in mscorlib.dll but was not handled in user code Additional information: String was not...
16
3222
by: Shawnk | last post by:
I would like to perform various boolean operations on bitmapped (FlagsAttribute) enum types for a state machine design as in; ------------------- enum portState { Unknown, Open,
19
14743
by: tshad | last post by:
I have a value in my sql table set to tinyint (can't set to bit). I am trying to move it into a boolean field in my program and have tried: isTrue = (int)dbReader and isTrue =...
0
7136
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
7018
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...
0
7182
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,...
1
6906
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
5490
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
4923
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
3110
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
3106
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
672
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.