Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calculate numeric data in textboxes???

Status
Not open for further replies.

RookieDBO

Technical User
Sep 20, 2001
83
0
0
CA
Hello. I need help in figuring out what is wrong with my code. I'm a vb beginner so bear with me. I'm trying to create a calculate command button. My simple application involves the following.

Textbox1 = 50
Textbox2 = 100
Textbox3 = 60

Calculate Button that would display the result in textbox4.

Here's my code.

TextBox4.Text = Val(TextBox7) + (TextBox5) + (TextBox6) * (1.15)

Unfortunately this produces "219" which is wrong. The
correct answer is "241.50".

Please help.

Thanks
RookieDBO

 
TextBox4.Text = Val(TextBox7) + val(TextBox5) + (val(TextBox6) * 1.15)

David Paulson

 
Thanks for the quick reply but that didn't solve the problem. Still produces "219". Any more suggestion.

Thanks,
RookieDBO
 
you need to look into the order of operations multiplication is done before addition unless parenthasis are used.

TextBox4.Text = (Val(TextBox7) + val(TextBox5) + val(TextBox6)) * 1.15

-Sean
 
Great! It worked. Thanks very much.

RookieDBO
 
I would not recommend using the VAL function. Use either Cdbl or Csng. There are some potential problems with the VAL function.

TextBox4.Text = (CDbl(TextBox7) + CDbl(TextBox5) + CDbl(TextBox6)) * 1.15
Dan Grogan
dan@siqual.com

"Absit prudentia nil rei publicae profitur."
Without common sense you ain't gonna have nothing.
 
Simply :
CLng(Val(Textbox7) + (Textbox5) + (Textbox6)) * (1.15)

VB automaticly change datatype to Integer (val() of as string)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top