473,890 Members | 1,380 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
----------------------------

blnGetAllFolder s = RadioButton1
blnGetAllFolder s = CheckBox1
....
If blnGetAllFolder s Then
....
-----------------------------
Resulting Error message:

An unhandled exception of
type 'System.Invalid CastException' occurred in
microsoft.visua lbasic.dll

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

try:

blnGetAllFolder s = RadioButton1.Ch ecked
blnGetAllFolder s = CheckBox1.Check ed

hth

Peter
"BobAchgill " <an*******@disc ussions.microso ft.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
----------------------------

blnGetAllFolder s = RadioButton1
blnGetAllFolder s = CheckBox1
...
If blnGetAllFolder s Then
...
-----------------------------
Resulting Error message:

An unhandled exception of
type 'System.Invalid CastException' occurred in
microsoft.visua lbasic.dll

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

Nov 21 '05 #2
"BobAchgill " <an*******@disc ussions.microso ft.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.
blnGetAllFolder s = RadioButton1
RadioButton1 is a variable containing an object reference (to the
RadioButton control). You are assigning this object reference
into the variable blnGetAllFolder s.

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).


blnGetAllFolder s = RadioButton1.Ch ecked

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
2539
by: greg | last post by:
Discussion is invited on the following proto-PEP. ------------------------------------------------------------- PEP ??? - Overloadable Boolean Operators ======================================== SUMMARY This PEP proposes an extension to permit objects to define their own
2
6932
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 a type mismatch. It is positively because of the boolean(java primitive)parameter. It goes fine if I change this parameter to int or String. This inteface has a lot more methods which works fine, it is just the
8
3272
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. Sauper, Jr. President Sauper Associates, Inc.
2
2361
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 inherited class I have one DataGridValueChangedEventHandler event handler. I am overriding Edit() to know the current state of the cell. I am overriding Paint() to know the if the user has been editing the cell. I am also overriding the Commit() to
10
13849
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 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
0
1386
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 enumerated values that configure the Boolean value of the underlying class. The issue is I have a confirmation box that shows changed fields in my collection, but its showing both the enum values and the underlying Boolean value...If I make my...
5
3438
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 call this function (infact there are two functions as described above)...
10
16444
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 recognized as a valid Boolean. Public Sub UpdateCustomer_DashboardGraphs(ByVal sender As Object, ByVal e As System.EventArgs)
16
3261
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
14833
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 = Convert.ToBoolean((int)dbReader)
0
9979
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
9825
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,...
1
10925
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
10467
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9638
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
8018
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
7171
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
6052
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3282
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.