as for exception - you used sum in your example, so did I of course with division it would be wise to have something like:
if val(eprem.Text)=0 then
TextBox4 = ""
else
TextBox4 = val(gross.Text)/val(eprem.Text)
end if
for several controls simple way would be to move all computations and result displaying in one procedure which could be called from each event handler, like:
Private Sub eprem_Change()
Call do_job
End Sub
Private Sub gross_AfterUpdate()
Call do_job
End Sub
Private Sub OptionButton1_Click()
Call do_job
End Sub
Private Sub OptionButton2_Click()
Call do_job
End Sub
Private Sub OptionButton3_Click()
Call do_job
End Sub
Private Sub OptionButton4_Click()
Call do_job
End Sub
Private Sub do_job()
If OptionButton1 Then
TextBox4.Value = Val(gross.Text) + Val(eprem.Text)
ElseIf OptionButton2 Then
TextBox4.Value = Val(gross.Text) - Val(eprem.Text)
ElseIf OptionButton3 Then
TextBox4.Value = Val(gross.Text) * Val(eprem.Text)
ElseIf OptionButton4 Then
If Val(eprem.Text) <> 0 Then
TextBox4.Value = Val(gross.Text) / Val(eprem.Text)
Else
TextBox4.Value = "zero in eprem"
End If
End If
End Sub
note that in gross field I used AfterUpdate event handler (so do_job is called after finished editing, while in eprem i left Change (do_job called after each change within)
I added 4 more controls just to show that all computations are done in one procedure taking into account state all controls on the form.
Bookmarks