Click to See Complete Forum and Search --> : Equations with variables
RIISE
January 14th, 2010, 08:00 AM
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.
Cimperiali
January 14th, 2010, 08:47 AM
for example:
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...
Marraco
January 14th, 2010, 09:25 AM
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.
for example:
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
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.
ddclondon
January 15th, 2010, 01:45 AM
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
HanneSThEGreaT
January 15th, 2010, 07:03 AM
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...
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.