dimanche 10 mai 2015

Add a cancel button to input box VB

I have made a simple calculator and I would like to know if you put in a string instead of a double and if you press close or not. The program is a simple calculator where the menu is a box with buttons for addition, subtraction, multiplication, and division. I would like it if you enter a string a messagebox pops up that tells you to enter a number and when you enter an empty message or click cancel it takes you back to the start of the program. Here is the code

Public Class CalcForm
    Property num1 As Double = Nothing
    Property num2 As Double = Nothing
    Private Sub CalcForm_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    End Sub
    Private Sub Addition_Click(sender As Object, e As EventArgs) Handles Addition.Click
        Getnum()
        Dim Answer As Double = num1 + num2
        MessageBox.Show("The answer is " & Answer, "Answer")
    End Sub
    Private Sub Subtraction_Click(sender As Object, e As EventArgs) Handles Subtraction.Click
        Getnum()
        Dim Answer As Double = num1 - num2
        MessageBox.Show("The answer is " & Answer, "Answer")
    End Sub
    Private Sub Multiplication_Click(sender As Object, e As EventArgs) Handles Multiplication.Click
        Getnum()
        Dim Answer As Double = num1 * num2
        MessageBox.Show("The answer is " & Answer, "Answer")
    End Sub
    Private Sub Division_Click(sender As Object, e As EventArgs) Handles Division.Click
        Getnum()
        Dim Answer As Double = num1 / num2
        MessageBox.Show("The answer is " & Answer, "Answer")
    End Sub
    Private Sub Getnum()
        num1 = InputBox("Enter your first number", "Number 1")
        num2 = InputBox("Enter your second number", "Number 2")
    End Sub
End Class

Aucun commentaire:

Enregistrer un commentaire