[RESOLVED] [2005] math on multiple textboxes show in another
Hi Everyone, I will state the obvious first, I am new here, and new to programming. I have been in construction for years, I had an idea and I am trying to do some things in VB, I have done OK so far. However I am stuck with some math items.
ON My DB and form I have as many as 7 textbox fields I want to do math on and have the answer appear in another textbox at the bottom of my form.
Raw math lools like this:
textbox5 - (textbox1 + textbox2) - textbox6 I want the answer to show in textbox20
this is similar but:
textbox5 - (textbox1 + textbox2) - textbox6 / textbox8 I want the answer to show in textbox21
_______________________________________________________
I started a new project to test with just 3 boxes just to try and get it to show the answer This was the first step in baby steps - and started with this
Dim A As Double = TextBox1.Text
Dim B As Double = TextBox2.Text
Dim C As Double
Int(A = Convert.ToInt32(TextBox1.Text))
Int(B = Convert.ToInt32(TextBox2.Text))
Int(C = Convert.ToInt32(TextBox2.Text))
Int(C = A + B)
TextBox3.Text = Convert.ToInt32(C)
But it just returns a zero? I am sure I have the whole thing wrong.
Re: math on multiple textboxes show in another
Welcome to VB Forums.
Here is the code:
VB Code:
textbox20.Text = Val(textbox5.Text) - (Val(TextBox1.Text) + Val(TextBox2.Text)) - Val(textbox6.Text)
textbox21.Text = Val(textbox5.Text) - (Val(TextBox1.Text) + Val(TextBox2.Text)) - Val(textbox6.Text) / Val(textbox8.Text)
Re: math on multiple textboxes show in another
Wow, I was Certainly making it more difficult than it needed to be. Thank You.
I am finding that it is still returning a Zero. However I did dtermine that it is only doing it on the fields that are "money"
For instance:
TLostTextBox.Text = Val(TentriesTextBox.Text) + Val(TPlayedTextBox.Text)
With ALL 3 of the boxes being "money" fields
It works fine on all other number type fields?
Re: math on multiple textboxes show in another
are u inputting a currency value like $ in the textbox? if you are, it will never never work the value will return zero because your app will read it as string bcoz, there are values inputted other than numeric values in your textbox.
Re: math on multiple textboxes show in another
what are the values you have in the above three text boxes?
Re: math on multiple textboxes show in another
Well, in answer to both questions I think
Since the 2 boxes I am trying to "add" together are Money, after I input data and tab it looks like this $500.00 and $50.00 respectively
Re: math on multiple textboxes show in another
Quote:
Originally Posted by lerroux
are u inputting a currency value like $ in the textbox? if you are, it will never never work the value will return zero because your app will read it as string bcoz, there are values inputted other than numeric values in your textbox.
And you are offering the solution to be... It will never work?
Re: math on multiple textboxes show in another
try it like this:
VB Code:
ccur(trim(text1.text)) + ccur(trim(text2.text))
Re: math on multiple textboxes show in another
Quote:
Originally Posted by page_up
And you are offering the solution to be... It will never work?
yes it will :D
Re: math on multiple textboxes show in another
Quote:
Originally Posted by lerroux
try it like this:
VB Code:
ccur(trim(text1.text)) + ccur(trim(text2.text))
Is this what you mean? My appologies for being so new at this.
TLostTextBox.Text = CCur(Trim(TBuyTextBox.Text)) + ccur(Trim(TVigTextBox.Text))
The ccur are blue squiggled - not declared?
Re: math on multiple textboxes show in another
yes it's what i mean... you dont need to declare that, its a vb function just like val(), format() etc.
Re: math on multiple textboxes show in another
Quote:
Originally Posted by lerroux
yes it's what i mean... you dont need to declare that, its a vb function just like val(), format() etc.
That's what I thought, but I am getting build errors?
Error 1 Name 'ccur' is not declared. line 570
Error 2 Name 'ccur' is not declared. line 570
Re: math on multiple textboxes show in another
can you please post the entire code?
what vb version are you using anyway?
Re: math on multiple textboxes show in another
Quote:
Originally Posted by lerroux
can you please post the entire code?
what vb version are you using anyway?
Vb 2005
There really isn't any "code" I built my DB, I built my form with my fields and this is literaly the first thing outside of initial creation I was trying to accomplish. I have been using it as a raw DB with no calculations up to this point.
VB Code:
Private Sub TWonLostTextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TWonLostTextBox.TextChanged
TWonLostTextBox.Text = ccur(Trim(TBuyInTextBox.Text)) + ccur(Trim(THouseVigTextBox.Text))
End Sub
Re: math on multiple textboxes show in another
i'm not sure you can use ccur in vb 2005, im doing this in vb6... try posting your question in vb.net forum... :D
Re: math on multiple textboxes show in another
OK I am damn close, Thanks to your help I am tweaking it and slowly getting there. However.
VB Code:
TWonLostTextBox.Text = FormatCurrency(Trim(TBuyInTextBox.Text)) + FormatCurrency(Trim(THouseVigTextBox.Text))
BUT... this is how it comes out
$500.00$50.00
it concatenantes them? really odd. but oh so close. any idea
Re: [2005] math on multiple textboxes show in another
Re: [2005] math on multiple textboxes show in another
Here's the "proper" .NET way:
VB Code:
Dim val1 As Decimal
Dim val2 As Decimal
If Decimal.TryParse(Me.TextBox1.Text, Globalization.NumberStyles.Currency, Nothing, val1) AndAlso _
Decimal.TryParse(Me.TextBox2.Text, Globalization.NumberStyles.Currency, Nothing, val2) Then
Me.TextBox3.Text = (val1 + val2).ToString("c")
Else
MessageBox.Show("Please enter two valid currency values.")
End If
Re: [2005] math on multiple textboxes show in another
I think it would be simpler to use Replace (assuming Replace still exists in .Net - I've forgotten):
VB Code:
TLostTextBox.Text = FormatCurrency(Val(Replace(Trim(TBuyTextBox.Text), "$", "")) + Val(Replace(Trim(TVigTextBox.Text), "$", "")))
Re: [2005] math on multiple textboxes show in another
Quote:
Originally Posted by Al42
I think it would be simpler to use Replace (assuming Replace still exists in .Net - I've forgotten):
VB Code:
TLostTextBox.Text = FormatCurrency(Val(Replace(Trim(TBuyTextBox.Text), "$", "")) + Val(Replace(Trim(TVigTextBox.Text), "$", "")))
If you have different currency symbols then what you will do? let's say the user have Euro symbol, pound symbol, etc. replacing the currency symbol is not the correct way, I think.
Re: [2005] math on multiple textboxes show in another
Quote:
Originally Posted by jmcilhinney
Here's the "proper" .NET way:
VB Code:
Dim val1 As Decimal
Dim val2 As Decimal
If Decimal.TryParse(Me.TextBox1.Text, Globalization.NumberStyles.Currency, Nothing, val1) AndAlso _
Decimal.TryParse(Me.TextBox2.Text, Globalization.NumberStyles.Currency, Nothing, val2) Then
Me.TextBox3.Text = (val1 + val2).ToString("c")
Else
MessageBox.Show("Please enter two valid currency values.")
End If
That did it. Thank you, very much! Thanks to all who helped.
As newbie, I just want to say that an answer like this that seems so simple to the expert solved about 30 future questions from a newbie like me. I am able to learn from the answer and tweak it to fit so many other scenarios I have. Thank you for your time to help me.
Re: [2005] math on multiple textboxes show in another
When you have received an answer to your question, please mark it as resolved using the Thread Tools menu.