Results 1 to 9 of 9

Thread: making menu strips disable code?

  1. #1
    ParaChase is offline VB.NET Forum Newbie
    .NET Framework
    .NET 4.0
    Join Date
    Jun 2012
    Posts
    8
    Reputation
    0

    making menu strips disable code?

    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!

  2. #2
    jmcilhinney's Avatar
    jmcilhinney is offline VB.NET Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Aug 2004
    Location
    Sydney, Australia
    Posts
    11,336
    Reputation
    1543
    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.

  3. #3
    ParaChase is offline VB.NET Forum Newbie
    .NET Framework
    .NET 4.0
    Join Date
    Jun 2012
    Posts
    8
    Reputation
    0
    So could I use a check box to determine the boolean variable or not?

  4. #4
    jmcilhinney's Avatar
    jmcilhinney is offline VB.NET Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Aug 2004
    Location
    Sydney, Australia
    Posts
    11,336
    Reputation
    1543
    Let's work through that question. How does a CheckBox work? How do you make use of one in code?

  5. #5
    ParaChase is offline VB.NET Forum Newbie
    .NET Framework
    .NET 4.0
    Join Date
    Jun 2012
    Posts
    8
    Reputation
    0
    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?

  6. #6
    jmcilhinney's Avatar
    jmcilhinney is offline VB.NET Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Aug 2004
    Location
    Sydney, Australia
    Posts
    11,336
    Reputation
    1543
    Quote Originally Posted by ParaChase View Post
    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.
    Quote Originally Posted by ParaChase View Post
    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.

  7. #7
    ParaChase is offline VB.NET Forum Newbie
    .NET Framework
    .NET 4.0
    Join Date
    Jun 2012
    Posts
    8
    Reputation
    0
    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?

  8. #8
    jmcilhinney's Avatar
    jmcilhinney is offline VB.NET Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Aug 2004
    Location
    Sydney, Australia
    Posts
    11,336
    Reputation
    1543
    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.

  9. #9
    ParaChase is offline VB.NET Forum Newbie
    .NET Framework
    .NET 4.0
    Join Date
    Jun 2012
    Posts
    8
    Reputation
    0
    got it! thanks!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Harvest time tracking