|
-
May 11th, 2006, 02:33 AM
#1
Thread Starter
Junior Member
[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.
Last edited by Hack; May 11th, 2006 at 06:35 AM.
Reason: Added Version
-
May 11th, 2006, 02:47 AM
#2
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)
-
May 11th, 2006, 03:30 AM
#3
Thread Starter
Junior Member
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?
-
May 11th, 2006, 03:41 AM
#4
Fanatic Member
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.
WARNING: Excessive coding is dangerous to your health... if symptoms persist insult your doctor...
-
May 11th, 2006, 03:41 AM
#5
Re: math on multiple textboxes show in another
what are the values you have in the above three text boxes?
-
May 11th, 2006, 03:47 AM
#6
Thread Starter
Junior Member
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
-
May 11th, 2006, 03:49 AM
#7
Thread Starter
Junior Member
Re: math on multiple textboxes show in another
 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?
-
May 11th, 2006, 03:50 AM
#8
Fanatic Member
Re: math on multiple textboxes show in another
try it like this:
VB Code:
ccur(trim(text1.text)) + ccur(trim(text2.text))
WARNING: Excessive coding is dangerous to your health... if symptoms persist insult your doctor...
-
May 11th, 2006, 03:51 AM
#9
Fanatic Member
Re: math on multiple textboxes show in another
 Originally Posted by page_up
And you are offering the solution to be... It will never work?
yes it will
WARNING: Excessive coding is dangerous to your health... if symptoms persist insult your doctor...
-
May 11th, 2006, 04:08 AM
#10
Thread Starter
Junior Member
Re: math on multiple textboxes show in another
 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?
-
May 11th, 2006, 04:27 AM
#11
Fanatic Member
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.
WARNING: Excessive coding is dangerous to your health... if symptoms persist insult your doctor...
-
May 11th, 2006, 04:32 AM
#12
Thread Starter
Junior Member
Re: math on multiple textboxes show in another
 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
-
May 11th, 2006, 04:36 AM
#13
Fanatic Member
Re: math on multiple textboxes show in another
can you please post the entire code?
what vb version are you using anyway?
WARNING: Excessive coding is dangerous to your health... if symptoms persist insult your doctor...
-
May 11th, 2006, 04:43 AM
#14
Thread Starter
Junior Member
Re: math on multiple textboxes show in another
 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
-
May 11th, 2006, 04:45 AM
#15
Fanatic Member
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...
WARNING: Excessive coding is dangerous to your health... if symptoms persist insult your doctor...
-
May 11th, 2006, 04:58 AM
#16
Thread Starter
Junior Member
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
-
May 11th, 2006, 06:35 AM
#17
Re: [2005] math on multiple textboxes show in another
-
May 11th, 2006, 07:29 AM
#18
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
-
May 11th, 2006, 10:21 AM
#19
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), "$", "")))
The most difficult part of developing a program is understanding the problem.
The second most difficult part is deciding how you're going to solve the problem.
Actually writing the program (translating your solution into some computer language) is the easiest part.
Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.
Please Help Us To Save Ana
-
May 11th, 2006, 11:46 AM
#20
Re: [2005] math on multiple textboxes show in another
 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.
-
May 11th, 2006, 02:44 PM
#21
Thread Starter
Junior Member
Re: [2005] math on multiple textboxes show in another
 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.
Last edited by page_up; May 11th, 2006 at 02:51 PM.
-
May 11th, 2006, 04:39 PM
#22
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|