This userform code assumes four text boxes,
TextBox1 holds a numeral
TextBox2 holds a symbol; + - * / ^
TextBox3 holds a numeral
TextBox4 will display the result of the calculation.
Private Sub TextBox1_Change()
Call updateTextBoxes
End Sub
Private Sub TextBox2_Change()
Call updateTextBoxes
End Sub
Private Sub TextBox3_Change()
Call updateTextBoxes
End Sub
Sub updateTextBoxes()
With Me
.TextBox4.Text = vbNullString
Select Case Left(Trim(.TextBox2.Text), 1)
Case Is = "+"
.TextBox4.Text = CStr(Val(.TextBox1.Text) + Val(.TextBox3.Text))
Case Is = "-"
.TextBox4.Text = CStr(Val(.TextBox1.Text) - Val(.TextBox3.Text))
Case Is = "*"
.TextBox4.Text = CStr(Val(.TextBox1.Text) * Val(.TextBox3.Text))
Case Is = "/"
If Val(.TextBox3.Text) = 0 Then
.TextBox4.Text = "#DIV/0"
Else
.TextBox4.Text = CStr(Val(.TextBox1.Text) / Val(.TextBox3.Text))
End If
Case Is = "^"
On Error Resume Next
.TextBox4.Text = CStr(Val(.TextBox1.Text) ^ Val(.TextBox3.Text))
On Error GoTo 0
End Select
End With
End Sub
Bookmarks