making menu strips disable code?

ParaChase

Member
Joined
Jun 17, 2012
Messages
8
Programming Experience
Beginner
Is it possible for a menu to disable code? If so, what is it? I'm starting a project that converts Fahrenheit to Celsius. I want to have the user to have the option of making the calculator round off or not. The project can already convert. I'm just adding extras.

Thanks!
 
There's no such thing as disabling code. What you need is an If statement. You test the value of a Boolean variable and do one thing if it's True and another if it's False. An appropriate name for your variable would be 'roundOff' or the like. Your menu item (or whatever) would then simply assign the appropriate value to that variable.
 
Well, you find it in the toolbox, then put it in the place you want to. Then you double click it to put it into the code. From that, you can have it run if the box is "checked", and if it isn't, it doesn't run the function, I don't have my code with me, but I can look at it when I get home. Also, aren't Radio Boxes basically the same thing?
 
From that, you can have it run if the box is "checked", and if it isn't, it doesn't run the function
That's the important part. The Checked property is basically bound to the visual state of the control and it is type Boolean. You don't need a separate variable because that property is your flag.
Also, aren't Radio Boxes basically the same thing?
CheckBoxes and RadioButtons are similar except that each CheckBox is completely independent of any other CheckBoxes while RadioButtons in a group are related in that no more than one can be checked at a time, i.e. checking one will uncheck all others. RadioButtons are in the same group when they have the same Parent control.
 
Ok, I think I see. So the user could use a checkbox to chose whether he wants to round off his conversions or not. If the box is not selected, (i.e. the temperature will round), then run a particular section of code. If it is selected, then run a separate, but similar code that does round the numbers. Am I right?
 
You am right, except that it's "checked" rather than "selected". That said, what you would probably do is just calculate the actual value with full precision first, then round off if the box is checked.
 
Back
Top