Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

ASP.NET 2005 - String.Format doesn't affect a text box!

Posted on 2008-06-20
5
Medium Priority
?
549 Views
Last Modified: 2013-11-26
Hi,

I am trying to format some numbers in my text box by using:

Me.Subscribed_QTY.Text = Format(Me.Subscribed_QTY.Text.ToString, "{0:##,#}")

However, if the value of the text box is 1000 it doesn't change! What should I do?

0
Comment
Question by:feesu
  • 2
  • 2
5 Comments
 
LVL 10

Expert Comment

by:NeoTeq
ID: 21833537
You will need to convert it to a number before it can format it as one.
Me.Subscribed_QTY.Text = CType(Me.Subscribed_QTY.Text, Decimal).ToString("{0:##,#}")

Open in new window

0
 

Author Comment

by:feesu
ID: 21835748
Hi NeoTeq,

I tried what you sent me. It doesn't work.
0
 
LVL 22

Accepted Solution

by:
prairiedog earned 250 total points
ID: 21847739
If the value of the text box is always Integer, then you can try:
Me.Subscribed_QTY.Text = String.Format("{0:##,#}", Int32.Parse(Me.Subscribed_QTY.Text))
If the value of the text box is always Decimal, then you can try:
Me.Subscribed_QTY.Text = String.Format("{0:##,#}", Decimal.Parse(Me.Subscribed_QTY.Text))

The second one will also work for Integer values.
0
 
LVL 22

Expert Comment

by:prairiedog
ID: 21885207
If you got your answer, will you please close the question?
0
 

Author Comment

by:feesu
ID: 21895827
prairiedog,

I have tested this code, and observed the following:

1- The formatted number inside the text box cannot be used in calculations; 60,000 is read as 60 !

2- I needed to format the text box even if it's empty but  I am getting an error. How can I do that?

Currently I call this:
 Me.Subscribed_QTY.Text = String.Format("{0:##,#}", Decimal.Parse(Val(Me.Subscribed_QTY.Text)))



Thanks for helping me cuz I'm new to this.
0

Featured Post

Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

Question has a verified solution.

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

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
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 …
Integration Management Part 2
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

972 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