Radio buttons - best practice

  • Thread starter Thread starter John Dann
  • Start date Start date
J

John Dann

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
 
John Dann said:
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
 
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
 
Back
Top