/ Forside / Teknologi / Udvikling / VB/Basic / Nyhedsindlæg
Login
Glemt dit kodeord?
Brugernavn

Kodeord


Reklame
Top 10 brugere
VB/Basic
#NavnPoint
berpox 2425
pete 1435
CADmageren 1251
gibson 1230
Phylock 887
gandalf 836
AntonV 790
strarup 750
Benjamin... 700
10  tom.kise 610
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



Søg
Reklame
Statistik
Spørgsmål : 177501
Tips : 31968
Nyheder : 719565
Indlæg : 6408522
Brugere : 218887

Månedens bedste
Årets bedste
Sidste års bedste