Groups | Blog | Home
all groups > dotnet general > october 2004 >

dotnet general : Q: Converting CheckBox.Checked to an int?



Scott M.
10/26/2004 4:51:53 PM
VB.NET:

CType(checkbox.checked, Integer)


"Visual Systems AB (Martin Arvidsson)" <martin.arvidsson@vsab.net> wrote in
message news:%23ycwLv5uEHA.1452@TK2MSFTNGP11.phx.gbl...
[quoted text, click to view]

Scott M.
10/26/2004 5:25:53 PM
No, you shouldn't have to test it. You should be able to cast it into an
integer and get back 0 or 1 directly.


[quoted text, click to view]

Visual Systems AB \(Martin Arvidsson\)
10/26/2004 10:38:44 PM
Hi!

How do I convert a CheckBox.Checked to an int?

Regards

Martin Arvidsson

Morten Wennevik
10/26/2004 10:51:00 PM
Hi Martin,

To get an int value out of you can do something like

int i = CheckBox.Checked ? 1 : 0;

A boolean value can't be translated to any other value, so you will need
to test it, if true use 1, otherwise use 0.

--
Happy Coding!
Morten Wennevik
10/27/2004 7:20:59 AM
[quoted text, click to view]

To add to this, there is no CType in C#, but you get the same effect using
Convert.ToInt32(bool)

--
Happy Coding!
AddThis Social Bookmark Button