CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Oct 2001
    Posts
    12

    Need help with Code for a Calculator?

    Hi everyone! I need a little help with a calculator i am developing. Heres the layout...... 3 text boxes(each one labeled firstnumber,secondnumber, and product). Also i have 4 option buttons(add,subract,multiply, and divide) and i have one command button that calculates the totals from the first two text boxes. Now how do i write the code for the option buttons so that when i click each one of them they will add , sub, multiply and divide. When i try to write the code different ways i keep getting compile error. Also do i put most of the code in the command button, so when i click it the input in the first two text boxes either adds them, subtracts them, multiplys or divides?? Thanks for any help you can give me.


  2. #2
    Join Date
    Apr 2000
    Location
    South Carolina,USA
    Posts
    2,210

    Re: Need help with Code for a Calculator?

    put the code in the command button click event. there you look to see what option button is checked and perform associated operation.

    John G

  3. #3
    Join Date
    Jan 2000
    Location
    Olen, Belgium
    Posts
    2,477

    Re: Need help with Code for a Calculator?

    Something like this maybe?


    private Sub Command1_Click()
    Select Case true
    Case optAdd
    Text3.Text = Val(Text1.Text) + Val(Text2.Text)
    Case optSub
    Text3.Text = Val(Text1.Text) - Val(Text2.Text)
    Case optMul
    Text3.Text = Val(Text1.Text) * Val(Text2.Text)
    Case optDiv
    Text3.Text = Val(Text1.Text) / Val(Text2.Text)
    End Select
    End Sub



    Note to merrion: I used your if-then-elseif-to-select-case method you posted on http://www.vbcodelibrary.co.uk/board, and I like it!



    Tom Cannaerts
    [email protected]

    Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to produce bigger and better idiots. So far, the universe is winning -- Rich Cook
    Tom Cannaerts
    email: [email protected]
    www.tom.be (dutch site)

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

Featured