Results 1 to 22 of 22

Thread: [RESOLVED] [2005] math on multiple textboxes show in another

  1. #1

    Thread Starter
    Junior Member
    Join Date
    May 2006
    Location
    So. California
    Posts
    26

    Resolved [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

  2. #2
    Frenzied Member cssriraman's Avatar
    Join Date
    Jun 2005
    Posts
    1,465

    Re: math on multiple textboxes show in another

    Welcome to VB Forums.

    Here is the code:
    VB Code:
    1. textbox20.Text = Val(textbox5.Text) - (Val(TextBox1.Text) + Val(TextBox2.Text)) - Val(textbox6.Text)
    2.  
    3. textbox21.Text = Val(textbox5.Text) - (Val(TextBox1.Text) + Val(TextBox2.Text)) - Val(textbox6.Text) / Val(textbox8.Text)
    CS

  3. #3

    Thread Starter
    Junior Member
    Join Date
    May 2006
    Location
    So. California
    Posts
    26

    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?

  4. #4
    Fanatic Member lerroux's Avatar
    Join Date
    Nov 2005
    Location
    Welcome to the darkside... we have cookies
    Posts
    646

    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...

  5. #5
    Frenzied Member cssriraman's Avatar
    Join Date
    Jun 2005
    Posts
    1,465

    Re: math on multiple textboxes show in another

    what are the values you have in the above three text boxes?
    CS

  6. #6

    Thread Starter
    Junior Member
    Join Date
    May 2006
    Location
    So. California
    Posts
    26

    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

  7. #7

    Thread Starter
    Junior Member
    Join Date
    May 2006
    Location
    So. California
    Posts
    26

    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?

  8. #8
    Fanatic Member lerroux's Avatar
    Join Date
    Nov 2005
    Location
    Welcome to the darkside... we have cookies
    Posts
    646

    Re: math on multiple textboxes show in another

    try it like this:
    VB Code:
    1. ccur(trim(text1.text)) + ccur(trim(text2.text))
    WARNING: Excessive coding is dangerous to your health... if symptoms persist insult your doctor...

  9. #9
    Fanatic Member lerroux's Avatar
    Join Date
    Nov 2005
    Location
    Welcome to the darkside... we have cookies
    Posts
    646

    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
    WARNING: Excessive coding is dangerous to your health... if symptoms persist insult your doctor...

  10. #10

    Thread Starter
    Junior Member
    Join Date
    May 2006
    Location
    So. California
    Posts
    26

    Re: math on multiple textboxes show in another

    Quote Originally Posted by lerroux
    try it like this:
    VB Code:
    1. 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?

  11. #11
    Fanatic Member lerroux's Avatar
    Join Date
    Nov 2005
    Location
    Welcome to the darkside... we have cookies
    Posts
    646

    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...

  12. #12

    Thread Starter
    Junior Member
    Join Date
    May 2006
    Location
    So. California
    Posts
    26

    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

  13. #13
    Fanatic Member lerroux's Avatar
    Join Date
    Nov 2005
    Location
    Welcome to the darkside... we have cookies
    Posts
    646

    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...

  14. #14

    Thread Starter
    Junior Member
    Join Date
    May 2006
    Location
    So. California
    Posts
    26

    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:
    1. Private Sub TWonLostTextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TWonLostTextBox.TextChanged
    2.                 TWonLostTextBox.Text = ccur(Trim(TBuyInTextBox.Text)) + ccur(Trim(THouseVigTextBox.Text))
    3.     End Sub

  15. #15
    Fanatic Member lerroux's Avatar
    Join Date
    Nov 2005
    Location
    Welcome to the darkside... we have cookies
    Posts
    646

    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...

  16. #16

    Thread Starter
    Junior Member
    Join Date
    May 2006
    Location
    So. California
    Posts
    26

    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:
    1. 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

  17. #17
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: [2005] math on multiple textboxes show in another

    Moved to VB.NET

  18. #18
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] math on multiple textboxes show in another

    Here's the "proper" .NET way:
    VB Code:
    1. Dim val1 As Decimal
    2.         Dim val2 As Decimal
    3.  
    4.         If Decimal.TryParse(Me.TextBox1.Text, Globalization.NumberStyles.Currency, Nothing, val1) AndAlso _
    5.            Decimal.TryParse(Me.TextBox2.Text, Globalization.NumberStyles.Currency, Nothing, val2) Then
    6.             Me.TextBox3.Text = (val1 + val2).ToString("c")
    7.         Else
    8.             MessageBox.Show("Please enter two valid currency values.")
    9.         End If
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  19. #19
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,691

    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:
    1. 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

  20. #20
    Frenzied Member cssriraman's Avatar
    Join Date
    Jun 2005
    Posts
    1,465

    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:
    1. 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.
    CS

  21. #21

    Thread Starter
    Junior Member
    Join Date
    May 2006
    Location
    So. California
    Posts
    26

    Re: [2005] math on multiple textboxes show in another

    Quote Originally Posted by jmcilhinney
    Here's the "proper" .NET way:
    VB Code:
    1. Dim val1 As Decimal
    2.         Dim val2 As Decimal
    3.  
    4.         If Decimal.TryParse(Me.TextBox1.Text, Globalization.NumberStyles.Currency, Nothing, val1) AndAlso _
    5.            Decimal.TryParse(Me.TextBox2.Text, Globalization.NumberStyles.Currency, Nothing, val2) Then
    6.             Me.TextBox3.Text = (val1 + val2).ToString("c")
    7.         Else
    8.             MessageBox.Show("Please enter two valid currency values.")
    9.         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.

  22. #22
    Frenzied Member cssriraman's Avatar
    Join Date
    Jun 2005
    Posts
    1,465

    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.
    CS

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width