CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Jan 2010
    Posts
    4

    Equations with variables

    Hi, so the problem i'm having is I have a 4 comboboxes with values connected to the items. I have textboxes set up so the values of the items show up. The items are concatenated ("£" & processor(0))

    The processor variable contains the number, so how would I add numerous variables together to display in another textbox.

  2. #2
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    Re: Equations with variables

    for example:
    Code:
    TextboxValueTot.text =CCur(textboxValueA.Text) + CCur(textboxValueB.Text)
    CCur will convert from string to currency. It might require a culture specification to match the
    currency symbol you're using...
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

  3. #3
    Join Date
    Mar 2007
    Location
    Argentina
    Posts
    579

    Re: Equations with variables

    Quote Originally Posted by RIISE View Post
    Hi, so the problem i'm having is I have a 4 comboboxes with values connected to the items. I have textboxes set up so the values of the items show up. The items are concatenated ("£" & processor(0))

    The processor variable contains the number, so how would I add numerous variables together to display in another textbox.
    Quote Originally Posted by Cimperiali View Post
    for example:
    Code:
    TextboxValueTot.text =CCur(textboxValueA.Text) + CCur(textboxValueB.Text)
    CCur will convert from string to currency. It might require a culture specification to match the
    currency symbol you're using...
    I tought of this
    Code:
                    Dim processor(10) As String
                    Dim total As Double = 0
                    For Each value As String In processor
                        total += CDbl(value.Replace("£", ""))
                    Next
    but CDbl() will also mess it, if the culture use an incompatible decimal separator. So is good idea to use CCur, and check culture anyway.
    [Vb.NET 2008 (ex Express)]

  4. #4
    Join Date
    Jan 2010
    Posts
    38

    Re: Equations with variables

    CDbl() will also mess it, if the culture use an incompatible decimal separator. So is good idea to use CCur, and check culture anyway.
    It's a problem particularly if users are permitted to enter the values - they can make a typo or decide to include the currency symbol and/or invalid decimal seperator.

    It always put my mind at rest to validate the entry to ensure that no extraneous characters were in the data particularly if you were not in cotrol of the source of the data. The following is long-winded but it works well particularly if used as a function:

    Dim intLoop As Integer
    Dim strChar As String
    Dim strNumeric As String
    Dim strData As String
    Dim strResult As String

    strResult = ""
    strData = Trim$(txtSource.Text)
    ' eg:
    strData = "£$%1234.56"
    ' Setup the allowable characters and special decimal separator here
    strNumeric = "0123456789."
    For intLoop = 1 To Len(strData)
    strChar = Mid$(strData, intLoop, 1)
    If InStr(strNumeric, strChar) > 0 Then
    strResult = strResult + strChar
    End If
    Next intLoop
    txtSource.Text = strResult

  5. #5
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,284

    Re: Equations with variables

    I'd also recommend using CCur. Whenever working with monetary values, you may never know which country the user is in. Having the proper currency symbols handled by the user's machine automatically, is just more proffessional.

    Just my opinion...

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

Featured