Thread: Userform
View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Stevie_mac Stevie_mac is offline
external usenet poster
 
Posts: 39
Default Userform

Dude, there is many ways to handle this sort of thing. This realy is basic stuff!
You say "does not work when either textbox1 or textbox2 is empty." - Check it!

The example you were given was a point in the right direction, you gotta check things
and handle exceptions like "textbox is empty", this is what you have to do to account for
people who try... "I wonder what will happen if i try to calculate..." "so and so + is a w@nker"
You know what i mean!

Sub DoMath()
dim r1, r2
on error goto FAIL
if TextBox1.Text = "" then
r1 = 0
else
r1 = Evaluate(TextBox1.Text)
End if

if TextBox2.Text = "" then
r2 = 0
else
r2 = Evaluate(TextBox3.Text)
End if

TextBox3.Text = r1 + r2

Exit Sub
FAIL:
msgbox "An error occured. Check your input"
End Sub

(TextBox2.Text)


"Silsila" wrote in message ...
Hi Rob,

Thank you for your reply. The first code to sum up in the
textbox works fine. Thank you again.

The second code i tried as
TextBox3.Text = Evaluate(TextBox1.Text) + Evaluate
(TextBox2.Text)

does not work when either textbox1 or textbox2 is empty.

Thanks for your help.

Regards

-----Original Message-----
Private Sub TextBox1_AfterUpdate()
TextBox1.Text = Evaluate(TextBox1.Text)
End Sub

If you wanted to post the result into a different

Textbox, say, TextBox2:
TextBox2.Text = Evaluate(TextBox1.Text)


--
Rob van Gelder - http://www.vangelder.co.nz/excel


"Silsila" wrote in

message
...
Hi All,

Can I add up in a text box in userform. For example the
user would type 10+12.50 in the text box and the text

box
would show 22.50

Also how can I add up few text boxes into another one.

Any
help is appreciated. Thanks in advance.

Regards



.