Results 1 to 18 of 18

Thread: [2008] simple question with my if statement.

Threaded View

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2008
    Posts
    10

    [2008] simple question with my if statement.

    hey

    I have made an if statement for when i error check for fields which are supposed to have numbers in it. Atm, my statement says that if either of the text boxes are blank display error and if they have 2 numbers work out the answer. I was wondering how i can get the code to display an error message (msgbox) when both the fields are text. I know for numbers it is "isnumeric" but i cant figure out how to say if it is text.

    when one of the text boxes is a letter, it displays error because the other one is blank, but if the first one has a letter and the second one has any character it doesnt display the error

    I only need that little bit and i should be able to put it in >.< its been plaguing me haha

    thanks in advance
    josh

    Private Sub btnCalculate1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate1.Click
    Message = txtNumber1.Text + "+" + txtNumber2.Text
    number1 = Val(txtNumber1.Text)
    number2 = Val(txtNumber2.Text)
    If IsNumeric(txtNumber1.Text) And IsNumeric(txtNumber2.Text) Then
    txtAnswer1.Text = Message + " = " + Str(number1 + number2)
    ElseIf (txtNumber1.Text = "" Or txtNumber2.Text = "") Then
    MsgBox("Please enter a valid number")

    End If
    End Sub
    Last edited by Jmack; Feb 12th, 2008 at 06:37 PM.

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