468,770 Members | 2,192 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,770 developers. It's quick & easy.

Q: Converting CheckBox.Checked to an int?

Hi!

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

Regards

Martin Arvidsson
Jul 21 '05 #1
4 10001
VB.NET:

CType(checkbox.checked, Integer)
"Visual Systems AB (Martin Arvidsson)" <ma**************@vsab.net> wrote in
message news:%2****************@TK2MSFTNGP11.phx.gbl...
Hi!

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

Regards

Martin Arvidsson

Jul 21 '05 #2
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 [C# MVP]
Jul 21 '05 #3
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.
"Morten Wennevik" <Mo************@hotmail.com> wrote in message
news:opsghv7agoklbvpo@pbn_computer...
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 [C# MVP]

Jul 21 '05 #4
On Tue, 26 Oct 2004 17:25:53 -0400, Scott M. <s-***@nospam.nospam> wrote:
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.


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

--
Happy Coding!
Morten Wennevik [C# MVP]
Jul 21 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by John Mullen | last post: by
4 posts views Thread by RodBillett | last post: by
4 posts views Thread by Visual Systems AB \(Martin Arvidsson\) | last post: by
3 posts views Thread by nologo | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.