Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hello everyone. I have a form which has about ten radio buttons. When the user doesnt make any selection, how do I catch this in code? I am presently doing the following since its only ten radio buttons, but what happens if I have a 100?! How do I loop all the radiobuttons checked status? Thanks.

If Me.RadioButton1.Checked = False And Me.RadioButon2.Checked = False And '.... continues for ALL the buttons
Then
MsgBox("Please make a selection")
End If

Posted

I am not sure about vb.net, I used to do this in vb6.

 

I assign radiobuttons (checkboxes more suitable) with array.

 

so, to check the value, i just use a loop to check one by one

George C.K. Low

Posted

That's VB6-Think. In VB.Net, much better to use logic like:


       Dim ctrl As Control
       For Each ctrl In Me.Controls
If TypeOf ctrl Is RadioButton Then
'  Action here
Next

Posted

also if you DO use the way you have you don't need to put false.

 

Just FYI so when you do other boolean style if statements

 

for false

 

if NOT me.radiobutton1.checked then

end if

 

for true

if me.radiobutton1.checked then

end if

Live as if you were to die tomorrow. Learn as if you were to live forever.
Gandhi

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...