|
-
Nov 23rd, 2010, 05:12 AM
#1
Thread Starter
New Member
[RESOLVED] Need help with code
I'm making a basic calculator program in Visual Basic 6. I have separate text input boxes for the operator and both the numbers for the equation. I've managed to code it so that if the user enters an incorrect character into the operator box, it will open up a message box and alert the user, rather than doing the calculation.
Here's the code I used for the message box alert for the operator input box:
Code:
Private Sub cmdCalc_Click()
Select Case txtOperator
Case "+"
lblResult = Val(txtNum1) + Val(txtNum2)
Case "-"
lblResult = Val(txtNum1) - Val(txtNum2)
Case "*"
lblResult = Val(txtNum1) * Val(txtNum2)
Case "/"
lblResult = Val(txtNum1) / Val(txtNum2)
Case Else
MsgBox ("Operator input error, please use +, -, / or *.")
End Select
End Sub
I want some similar code for the number text input box, so that if the user enters a letter, it opens up a message box in a similar way to the one for the operator. I've tried lots of things but can't seem to get it right. Anyone have any ideas?
Thanks in advance,
Godge.
-
Nov 23rd, 2010, 06:14 AM
#2
Re: Need help with code
The forum search here is always a good start. Here is one item that might get you started:
http://www.vbforums.com/showthread.p...=numeric+input
-
Nov 23rd, 2010, 06:29 AM
#3
Thread Starter
New Member
Re: Need help with code
Thanks Tyson, found some code in that thread that worked like a charm
-
Nov 23rd, 2010, 06:35 AM
#4
Re: Need help with code
I see you are fairly new here. At the top of the thread is a drop down called "Thread Tools" and an option to "Mark Thread Resolved". That keeps others from pulling it up to help. Thanks!
-
Nov 23rd, 2010, 10:33 AM
#5
Thread Starter
New Member
Re: [RESOLVED] Need help with code
Thanks, I've done that 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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|