|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Radio buttons - best practiceThere'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 I would only use a variable if a global is required for other forms/module
procedures. -- Show quoteHide quoteDennis 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 > "John Dann" <n***@prodata.co.uk> wrote in message This is reasonable. For an option that is on/off a checkbox is better but news:6114m25mu93tqijbbuah8r58nvimprr9k4@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.) 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 Generally it's bad practice to store the same data twice as it gives > 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? 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 Michael C wrote: Show quoteHide quote > "John Dann" <n***@prodata.co.uk> wrote in message > news:6114m25mu93tqijbbuah8r58nvimprr9k4@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
Saving the Color value into a string
How do I even start debugging this. User Interface Design - Books? Need for Speed naming conventions forced by VS.NET? Can a Decimal variable be set to "Not a Number" find number in a string Trouble displaying info from access db I need 2-3 books on VB.NET, Office automation. Any suggestions? ClickOnce program fails to run properly after update |
|||||||||||||||||||||||