Re: Using a String value as a RadioButton object reference

From: Cor (non_at_non.com)
Date: 03/30/04


Date: Tue, 30 Mar 2004 08:48:04 +0200

Hi Mike,

We did seen this question not for a long while, it was often in this
newsgroup

I type it here new watch typos.

I take the most simple one which asumes that the buttons are all direct on
the form, just to show you how.

When the buttons are on a panel or whatever, there are a lot alternatives
(recursion or whatever).

This is a winform sample in a webform it needs a little bit in an other way.
I did not write it direct in your sample, because I asume that will become
very long.

\\\
dim ctr as control
for each ctr in me.controls
    if typeof ctr is radiobutton then
        if directcast(ctr,radiobutton).name.substring(0) = "Mybuttonname"
        'do what you want to do with ctr.xxxx
        end if
    end if
next
///
I hope this helps?

Cor

"Mike Bazoo" <mike_bazoo@hotmail.com> schreef in bericht
news:62023689.0403292020.7ec480d0@posting.google.com...
> I am a novice vb.net programmer and hope someone can help me.
>
> For a questionnaire, I have several (100+) radio buttons whose names
> follow this standard:
> radAlways1, radAlways2, 3.. 10
> radUsually1, radUsually2, 3...10
> radSometimes1, radSometimes2, 3...10
> etc
>
> My ultimate goal is to loop through each one and do an action on the
> ones that are 'Checked'.
>
> In order to try to reduce the amount of code, I created Strings inside
> each loop which generate radio buttons names. Something like this:
>
> For intCount = 0 To 10
> strAlways = "radAlways" & intCount + 1
> strUsually = "radUsually" & intCount + 1
> strSometimes = "radSometimes" & intCount + 1
> strSeldom = "radSeldom" & intCount + 1
> strNever = "radNever" & intCount + 1
>
> ...'Rest of code here
> Next intCount
>
> This part actually works fine which the strings having the right radio
> buttons names in each loop iteration.
>
> Now, my question is: how can I use this correctly generated string as
> the RadioButton object in order to be able to call RadioButton's
> methods ('Checked' in particular)?
>
> For intCount = 0 To 2
> strAlways = "radAlways" & intCount + 1
> strUsually = "radUsually" & intCount + 1
> strSometimes = "radSometimes" & intCount + 1
>
> 'HERE IS WHERE I WANT TO USE THE STRING VALUE
> 'AS THE RADIOBUTTON IN ORDER TO CALL THE 'CHECKED' METHOD.
> 'I DO NOT WANT TO HARDCODE THE ACTUAL RADIOBUTTON OBJECT
> NAME.
> If radAlways1.Checked = True Then
> 'do something
> ElseIf radUsually1.Checked = True Then
> 'do something
> ElseIf radSometimes1.Checked = True Then
> 'do something
> End If
> Next intCount
>
> I am also open for other ideas on how to accomplish this.
> Thanks.