473,586 Members | 2,870 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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).Chec ked Then
strValue = rbarray(i).Text
End If
Next
Nov 20 '05 #1
2 1294
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.cont rols
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).Chec ked 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).Chec ked 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
6139
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 are no instructions on how to make checkboxes and radio buttons required. I've tried adding these to my form, but I'm having no luck. Anyone know...
6
3273
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 The problem i am facing is that i do not know how many yes/no radio groups will be generated
4
3239
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 can populate text boxes/textareas using this data no problem. What about radio buttons? If I have 2 of them named the same rb1 and rb1 with...
2
3225
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 is a text box, with the search button next to it, and at the bottom there are four check boxes. When the form loads one of the two radio buttons are...
4
11027
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 to: if one is clicked, its corresponding information will become available on another document, if it's not clicked no information will be...
2
11950
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 them each in a GroupBox. All the examples I saw from the books or from the web show me how to add static radio buttons at design, or dynamically at...
1
6865
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 grandtotal the costs ready for the selected items to be inserted back to the database. I did something like this before with Checkboxes, but...
3
2014
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 each). When I first start the program none of the radiobuttons are checked. I also have 4 buttons on the bottom of the page. For some reason,...
5
6689
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 = ConfigurationManager.ConnectionStrings.ConnectionString; protected void Page_Load(object sender, EventArgs e) { try
0
7839
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8215
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5710
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5390
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3836
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3864
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2345
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1448
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1179
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.