|
| checkbox array - repost Fra : brinckmartin |
Dato : 11-11-02 11:23 |
|
Hi everybody!
I would like to create a control array of eight checkboxes, and then
retrieve
all eight bits/checks in a single loop structure.
I'm a skilled VB6 programmer, but in VB .NET the Index property is no longer
accesible, so I'm having a really hard time doing this...
I would like to write like the following, but the syntax doesn't allow the
property "Checked", (what do I do now?):
Dim ctrl As Control
Dim m As String
Dim b(7) As Boolean
Dim n As Integer
For Each ctrl In Controls
b(n) = ctrl.Checked
n=n+1
Next
If anybody has got a clue, I'd like to hear.
Sincerely
Martin Axelsen
| |
Torben Frandsen (12-11-2002)
| Kommentar Fra : Torben Frandsen |
Dato : 12-11-02 10:17 |
|
"brinckmartin" <brinckmartin@hotmail.com> skrev
> I would like to write like the following, but the syntax doesn't allow the
> property "Checked", (what do I do now?):
Cast your Control to the appropriate type thus:
Dim ctl As Control
Dim chk As CheckBox
Dim b(7) As Boolean
Dim n As Integer
For Each ctl in Controls
If TypeOf ctl Is CheckBox Then ' Avoid InvalidCastExceptions
chk = ctl ' Gets you the Typecast
b(n) = ctl.Checked
n += 1
End If
Next ctl
Torben
| |
brinckmartin (12-11-2002)
| Kommentar Fra : brinckmartin |
Dato : 12-11-02 17:49 |
|
Torben Frandsen wrote:
>
> Cast your Control to the appropriate type thus:
>
> Dim ctl As Control
> Dim chk As CheckBox
> Dim b(7) As Boolean
> Dim n As Integer
>
> For Each ctl in Controls
> If TypeOf ctl Is CheckBox Then ' Avoid InvalidCastExceptions
> chk = ctl ' Gets you the Typecast
> b(n) = ctl.Checked
> n += 1
> End If
> Next ctl
>
> Torben
Wow, I think this might be the solution,
I'll write back tomorrow (after additional coding)
Thank you for writing
Martin
| |
Torben Frandsen (13-11-2002)
| Kommentar Fra : Torben Frandsen |
Dato : 13-11-02 10:07 |
|
"Torben Frandsen" <tf@belman.tryremovingthis.dk> skrev
Oops. Typo:
> b(n) = ctl.Checked
Should be:
b(n) = chk.checked
Torben
| |
|
|