Results 1 to 5 of 5

Thread: [RESOLVED] Need help with code

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2010
    Posts
    3

    Resolved [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.

  2. #2
    Wall Poster TysonLPrice's Avatar
    Join Date
    Sep 2002
    Location
    Columbus, Ohio
    Posts
    3,969

    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

  3. #3

    Thread Starter
    New Member
    Join Date
    Nov 2010
    Posts
    3

    Re: Need help with code

    Thanks Tyson, found some code in that thread that worked like a charm

  4. #4
    Wall Poster TysonLPrice's Avatar
    Join Date
    Sep 2002
    Location
    Columbus, Ohio
    Posts
    3,969

    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!

  5. #5

    Thread Starter
    New Member
    Join Date
    Nov 2010
    Posts
    3

    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
  •  



Click Here to Expand Forum to Full Width