|
-
January 14th, 2010, 09:00 AM
#1
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.
-
January 14th, 2010, 09:47 AM
#2
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.
-
January 14th, 2010, 10:25 AM
#3
Re: Equations with variables
 Originally Posted by RIISE
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.
 Originally Posted by Cimperiali
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)]
-
January 15th, 2010, 02:45 AM
#4
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
-
January 15th, 2010, 08:03 AM
#5
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|