Solved

TextBox Date format

Posted on 2004-03-30
7
901 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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Flash (http://en.wikipedia.org/wiki/Adobe_Flash) has evolved over the years to where it has become a masterful tool for displaying content screen.  It has excellent layout placement, UI precision as well as rendering capabilities. This, along with t…
A basic question.. “What is the Garbage Collector?” The usual answer given back: “Garbage collector is a background thread run by the CLR for freeing up the memory space used by the objects which are no longer used by the program.” I wondered …
This video discusses moving either the default database or any database to a new volume.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

746 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now