473,406 Members | 2,293 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Radio Buttons in Groupboxes - Code check

Hi

I have two radio buttons in a groupbox on a Windows form and have wrote the
code below to find out which button is selected. Can anyone tell me if
there is an easier / better way to code this as it seems a bit long?

Thanks

Rich

Dim rbarray As RadioButton()
Dim strValue As String

rbarray = new RadioButton() {rb1, rb2}

Dim i As Integer

For i = 0 To 1
If rbarray(i).Checked Then
strValue = rbarray(i).Text
End If
Next
Nov 20 '05 #1
2 1286
Hi Rich,

There are a lot of other methods, however your code very short and I think
there i nothing wrong with.

You can also do
\\
for each ctr as mygroupbox.controls
if ctr.Checked Then
strValue = ctr.Text
End If
Next
///
This you can do when there are sure there are only radiobuttons, otherwise
you have to put it in a
\\\
if typeof ctr is radiobutton then
......
end if
///
And than it is again longer

I hope this give some idea's?

Cor
Nov 20 '05 #2
On Tue, 27 Apr 2004 12:27:23 +0100, Rich wrote:
Hi

I have two radio buttons in a groupbox on a Windows form and have wrote the
code below to find out which button is selected. Can anyone tell me if
there is an easier / better way to code this as it seems a bit long?

Thanks

Rich

Dim rbarray As RadioButton()
Dim strValue As String

rbarray = new RadioButton() {rb1, rb2}

Dim i As Integer

For i = 0 To 1
If rbarray(i).Checked Then
strValue = rbarray(i).Text
End If
Next


Another point is inside the If, after setting the value, put Exit For.
Since only one radio button can be selected (all the others would bel
cleared) as soon as you find the one that is selected, there is no need to
continue looking:

For i = 0 To 1
If rbarray(i).Checked Then
strValue = rbarray(i).Text
Exit For
End If
Next
--
Chris

To send me an E-mail, remove the underscores and lunchmeat from my E-Mail
address.
Nov 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: sman | last post by:
Hi, I recently read this article on About.com on how to create required fields for a form: http://javascript.about.com/library/scripts/blformvalidate.htm Everything works great except that there...
6
by: Craig Keightley | last post by:
I have a page that has n number of radio groups (yes/No) how can i prevent the form being submitted if more than one radio group is not selected? By default all radio groups are unchecked ...
4
by: Jay | last post by:
I have a form used to submit data (no surprises there!). I'd like to be able to populate the same form with previously submitted data. The data lives in a database once submitted and using ASP I...
2
by: jimi_xyz | last post by:
Sorry if this isn't the correct group, i don't think there is a group for straight HTML. I am trying to create a type of search engine. There are two radio buttons at the top, in the middle there...
4
by: Jared | last post by:
Radio Button or Check Box and Event Procedures I need to insert either radio buttons or check boxes onto my form. I'm not sure which to use, or if there are other options. I am using the buttons...
2
by: James P. | last post by:
Help, I need to display radio buttons on a form. The data is from SQL table: each row in each table is displayed as a radio button. I have multiple SQL tables so I understand I need to put...
1
by: kenny8787 | last post by:
Hi, can anyone help here? I have the following code generated from a database, I want to have javascript calculate the costs of the selected items using radio buttons, subtotal the costs and...
3
by: tshad | last post by:
I have a form that has 2 sets of radiobuttons. As it happens I created 1 radiobutton and then copied it a pasted it 4 times. I have 4 radiobuttons split up into 2 groupboxes (2 radiobuttons...
5
by: satyabhaskar | last post by:
hi all, In my web page i have created radio buttons dynamically on to the page .....following is my code string Course, Semester, Section; int rowsCount; string con =...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.