I need to write a simpe calc. program to add, mutiply, subtract and divide. I want to have two textboxes that I enter numbers in and when I click a button, +,-,/ or * a third text box will display the result.
Rather than declaring my variables inside each instance of a click event I would like to declare them globally so I just need to perfom the calculation on them and display result. However declaring them globally doesn't work for me. I;ve tried the variables inside the btnAdd click event which works, but as I said I'd prefer to declare them onece globally. Anyone see where I'm going wrong?
Public Class Form1 Dim number1 As Double = CDbl(txtNum1.Text) Dim number2 As Double = CDbl(txtNum2.Text) Dim total As Double = txtTotal.Text Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click total = number1 + number2 lblOperator.Text = "+" End Sub End Class