|
-
October 15th, 2001, 11:06 AM
#1
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.
-
October 15th, 2001, 12:03 PM
#2
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
-
October 15th, 2001, 12:29 PM
#3
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|