Results 1 to 5 of 5

Thread: [RESOLVED] Calculator

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2012
    Posts
    4

    Resolved [RESOLVED] Calculator

    This is probably an easy question for you guys, but I'm just starting out and was making a calculator program with three checkboxes (lets say every checkbox has a price attached to it of $50) and two radiobuttons. Now, the checkboxes give users the option to combine certain products. If a user selects 1 checkbox and radiobutton nr 1 or 2 and clicks 'calculate' the calculated price shown in the textbox will be 50. (with two checkboxes, price will be 100) Thats fine.

    The point is, when the user clicks 'calculate'again (and again, and again), the textbox will show 50 50 50. I dont want the textbox to show more than one price. What i do want however is that the user will be able to check another checkbox (without clearing the form), which will make the price in the textbox change from 50 to 100. What it does now, is showing both the number 50 and 100 at the same time.

    I tried disabling the calculate button after one click, and by clicking the clear button it would be re-enabled. But that means users clear everything they did and cant just tick one extra checkbox to see the price difference.

    Hope this is clear, i wrote quite a lot of info for a small question.

    Summary: I want that when the calculate button is clicked, only one price will appear in the textbox. However, the price must be able to change when the user checks another checkbox and click calculate again.

    Thanks

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: Calculator

    That would suggest that you are appending each time instead of replacing. Each time the user clicks the Button to calculate, perform your calculation, call ToString on the result and then assign that result to the Text of the control you want to display it in.

  3. #3

    Thread Starter
    New Member
    Join Date
    Mar 2012
    Posts
    4

    Re: Calculator

    Thank you! That was indeed the problem, I had already called ToString, but for some reason I typed '+=' instead of just '='.

    Do you also happen to know how I can make sure that none of the two radio buttons is pre-selected when starting the application? The 'checked' property is already set to false for both of them, but for some reason the top radio button is always pre-selected. For my assignment, I have to input code that clears that selection, and it doesn't do that now..

    Thanks again!

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: Calculator

    I would guess that that RadioButton is the first control in the Tab order. Being so, it will get focus when the form is first displayed and a RadioButton is checked automatically when it gets focus. If that's so then you will either need to adjust your Tab order or else explicitly set Checked to False for that RadioButton in the form's Shown event handler, which is executed immediately after the form is first displayed.

  5. #5

    Thread Starter
    New Member
    Join Date
    Mar 2012
    Posts
    4

    Re: Calculator

    Thank you, that helped! Everything is working as it should now

Posting Permissions

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



Click Here to Expand Forum to Full Width