Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

TextBox Date format

Posted on 2004-03-30
7
Medium Priority
?
911 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

IP addresses can be stored in a database in any of several ways.  These ways may vary based on the volume of the data.  I was dealing with quite a large amount of data for user authentication purpose, and needed a way to minimize the storage.   …
This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

609 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