473,322 Members | 1,473 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,322 software developers and data experts.

Radio buttons - best practice

Is it reasonable practice to use a control to hold a variable value?

There's a (Boolean) flag that I want to allow the user to set or not
as they wish. This will be set either simply by a checkbox on the main
form of by a pair of radio buttons within a small groupbox. (These two
approaches are AFAICS equivalent but I prefer the radio buttons
because they show explicitly which of the two options has been
chosen.)

I was then going to declare a Boolean variable and set this according
to the state of the checkbox or radio button controls, changing the
value in the various click events etc.

But maybe this use of a separate variable is totally superfluous. When
I get to the point in the code where I need to know whether the flag
is set or not I could just check directly the state of the checkbox or
one of the option buttons. Is there any good reason not to go with
this simpler approach?

JGD
Nov 20 '06 #1
3 2137
I would only use a variable if a global is required for other forms/module
procedures.
--
Dennis in Houston
"John Dann" wrote:
Is it reasonable practice to use a control to hold a variable value?

There's a (Boolean) flag that I want to allow the user to set or not
as they wish. This will be set either simply by a checkbox on the main
form of by a pair of radio buttons within a small groupbox. (These two
approaches are AFAICS equivalent but I prefer the radio buttons
because they show explicitly which of the two options has been
chosen.)

I was then going to declare a Boolean variable and set this according
to the state of the checkbox or radio button controls, changing the
value in the various click events etc.

But maybe this use of a separate variable is totally superfluous. When
I get to the point in the code where I need to know whether the flag
is set or not I could just check directly the state of the checkbox or
one of the option buttons. Is there any good reason not to go with
this simpler approach?

JGD
Nov 21 '06 #2
"John Dann" <ne**@prodata.co.ukwrote in message
news:61********************************@4ax.com...
Is it reasonable practice to use a control to hold a variable value?

There's a (Boolean) flag that I want to allow the user to set or not
as they wish. This will be set either simply by a checkbox on the main
form of by a pair of radio buttons within a small groupbox. (These two
approaches are AFAICS equivalent but I prefer the radio buttons
because they show explicitly which of the two options has been
chosen.)
This is reasonable. For an option that is on/off a checkbox is better but
radio buttons are better for 2 seperate options. They should also be used if
there's potentially more than 2 options, even if there's only 2 at the mo.
I was then going to declare a Boolean variable and set this according
to the state of the checkbox or radio button controls, changing the
value in the various click events etc.

But maybe this use of a separate variable is totally superfluous. When
I get to the point in the code where I need to know whether the flag
is set or not I could just check directly the state of the checkbox or
one of the option buttons. Is there any good reason not to go with
this simpler approach?
Generally it's bad practice to store the same data twice as it gives
potential for each to be different. The only reason I would do this is for
speed but even in that case I would grab the value before the start of a
loop and discard it at the end.

In regards to what dennis said about accessing it globally, a seperate
variable might be necessary but only if the value needs to remain after the
form is closed.

Michael
Nov 21 '06 #3
I would avoid using radio buttons, they are a bit old fashioned and are
prone to interference. If you must use them and are still having
problems try spraying them with contact cleaner to eliminate any
corrosion from metal surfices, corrosion can disturb the electrical
current.

Hope this helps
The Grand Master

Michael C wrote:
"John Dann" <ne**@prodata.co.ukwrote in message
news:61********************************@4ax.com...
Is it reasonable practice to use a control to hold a variable value?

There's a (Boolean) flag that I want to allow the user to set or not
as they wish. This will be set either simply by a checkbox on the main
form of by a pair of radio buttons within a small groupbox. (These two
approaches are AFAICS equivalent but I prefer the radio buttons
because they show explicitly which of the two options has been
chosen.)

This is reasonable. For an option that is on/off a checkbox is better but
radio buttons are better for 2 seperate options. They should also be used if
there's potentially more than 2 options, even if there's only 2 at the mo.
I was then going to declare a Boolean variable and set this according
to the state of the checkbox or radio button controls, changing the
value in the various click events etc.

But maybe this use of a separate variable is totally superfluous. When
I get to the point in the code where I need to know whether the flag
is set or not I could just check directly the state of the checkbox or
one of the option buttons. Is there any good reason not to go with
this simpler approach?

Generally it's bad practice to store the same data twice as it gives
potential for each to be different. The only reason I would do this is for
speed but even in that case I would grab the value before the start of a
loop and discard it at the end.

In regards to what dennis said about accessing it globally, a seperate
variable might be necessary but only if the value needs to remain after the
form is closed.

Michael
Nov 21 '06 #4

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

Similar topics

6
by: amith | last post by:
hi, i have some 10 radio buttons meant to take the rating from the user. ex: 1 2 3 4 5 6 7 8 9 10 looks O O O O O O O O O O 1 2 3 4 5 6 7 8 9 10 features O O O O O O O O O O
1
by: Rick | last post by:
After being frustrated with this issue on several occasions I think I found the secret sauce for solving the issue after reading a few different messages about what others thought and trying a...
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...
5
by: Jan Smith | last post by:
I have a C# project that has a tab control with four tab pages. On each tab page is a set of three radio buttons (named radioButton1 through radioButton12). I would like to loop through the radio...
5
by: sam | last post by:
Hi all, I am dynamically creating a table rows and inerting radio buttons which are also dynamically created. Everything works fine in Firefox as expected. But I am not able to select radio...
5
by: Dabbler | last post by:
What is the best way to handle data interpolation between form controls and the actual sql data field. I have radio buttons that need to be interpreted, form values that have to be translated.....
2
by: JimS | last post by:
I am using DotNet 2.0 and Visual Studio 2005. The project is a web project. I am currently using an ObjectDataSource to populate a datagrid. The ObjectDataSource is configured to a function in a...
0
by: JimS | last post by:
I am using DotNet 2.0 and Visual Studio 2005. The project is a web project. I am currently using an ObjectDataSource to populate a datagrid. The ObjectDataSource is configured to a function in a...
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...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.