Solved

TextBox Date format

Posted on 2004-03-30
7
905 Views
Last Modified: 2008-02-01
Hello, I have formatted the value held in a textbox to type of currency.    
                 
      Format (me.txtTotal.Text, "currency")

I have various textboxes on the form each with similar currency value in them.  I want to be able to add up all the values in the textbox, e.g £23.50 + £5.34,  the problem is that the results that gets returned is zero (0),  because it (must then be) a string and not a numerical type datatype.

Is there a property that i can set that changes the default display of the textbox to a currency type but allows me to add up the values without having to pass then through a function to get values.  This can be done in VB 6 and Access Forms, is there a setting on the textbox property that would help me do this?

Thanks
0
Comment
Question by:sublimation
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 48

Expert Comment

by:Mikal613
ID: 10714329
cdbl(txtwhatever.text)
0
 
LVL 48

Expert Comment

by:Mikal613
ID: 10714340
You ca also use the InputMask

Of the MaskedEditControl and right click and goto properties and set the format and then you just do
Mask.Value
0
 
LVL 15

Expert Comment

by:SRigney
ID: 10714981
VB6 and Access also call the function to convert the string to a number, it just does it behind the scenes without you having to add the code for that.
0
How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

 
LVL 4

Author Comment

by:sublimation
ID: 10716193
I forgot to mention that i am using vb.net.  I cant seem to see the maskededitcontrol in vb.net
0
 
LVL 14

Expert Comment

by:ptakja
ID: 10716221
You can also try Double.Parse(txtbox.Text) which will return the value as a Double.

So, something like this:

Dim dblTotal as Double = Double.Parse(Textbox1.Text) + Double.Parse(TextBox2.Text)  + etc...

OR, perhaps a little more elegant:

Dim dboTotal as Double
' Copy TextBoxes in an array
Dim txtBoxes as TextBox() = {TextBox1, TextBox2, TextBox3, TextBox4, Textbox5}

' Loop through array adding up the values.
For ii as Integer = 0 To txtBoxes.Count -1
    dblTotal += Double.Parse(txtBoxes(ii))
Next



Jeff
0
 
LVL 4

Author Comment

by:sublimation
ID: 10723752
Hello, none of the above work since the values in the textboxes are strings, like "£34.25".
   
I want to have the value in the textbox as a currency, e.g £45.76, but then be able to add them up.  

Is there a way that a textbox will display any number entered into it as a currency and let you add up the values.

I am using VB.Net
0
 
LVL 14

Accepted Solution

by:
ptakja earned 250 total points
ID: 10724153
Got it.  Try this:

Format(CType(Decimal.Parse(TextBox1.Text, Globalization.NumberStyles.Currency) + Decimal.Parse(TextBox2.Text, Globalization.NumberStyles.Currency), String), "Currency")

My sample code in previous post rewritten as shown above:

Dim dblTotal as Decimal = Decimal.Parse(Textbox1.Text, Globalization.NumberStyles.Currency) + Double.Parse(TextBox2.Text, Globalization.NumberStyles.Currency)  + etc...

OR, perhaps a little more elegant:

Dim dboTotal as Double
' Copy TextBoxes in an array
Dim txtBoxes as TextBox() = {TextBox1, TextBox2, TextBox3, TextBox4, Textbox5}

' Loop through array adding up the values.
For ii as Integer = 0 To txtBoxes.Count -1
    dblTotal += Double.Parse(txtBoxes(ii), Globalization.NumberStyles.Currency)
Next

txtTotal.Text = Format(dbl.Total.ToString(), "Currency")
0

Featured Post

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question