PC Review


Reply
 
 
BobAchgill
Guest
Posts: n/a
 
      17th Mar 2005
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).
 
Reply With Quote
 
 
 
 
Peter Proost
Guest
Posts: n/a
 
      17th Mar 2005
Hi,

try:

blnGetAllFolders = RadioButton1.Checked
blnGetAllFolders = CheckBox1.Checked

hth

Peter


"BobAchgill" <(E-Mail Removed)> schreef in bericht
news:11f901c52ab7$14b16900$(E-Mail Removed)...
> 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).



 
Reply With Quote
 
Phill. W
Guest
Posts: n/a
 
      17th Mar 2005
"BobAchgill" <(E-Mail Removed)> wrote in message
news:11f901c52ab7$14b16900$(E-Mail Removed)...
> 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.


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
NotSupportedException Type.GetType (String, Boolean, Boolean) jonfroehlich Microsoft Dot NET Compact Framework 1 20th Apr 2006 02:44 PM
Use of boolean in If-Then =?Utf-8?B?U2NvdHQ=?= Microsoft Access Form Coding 2 5th Feb 2006 12:41 AM
No boolean object in VB.NET? How to check if a boolean has been explicitely defined then? Lucas Tam Microsoft VB .NET 10 12th Jun 2005 09:29 PM
Using NOT for boolean value Dave Microsoft Access Getting Started 2 10th May 2005 04:05 PM
#VALUE! instead of Boolean value Robin Clay Microsoft Excel Misc 1 18th Mar 2004 06:39 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:33 AM.