Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to format a Textbox ? **** Urgent ***

Status
Not open for further replies.

cyberdyne

Programmer
May 1, 2001
173
0
0
IN
Hello firends,

I have a problem with text box formatting.

I want a numeric value to be formated as x,xx,xxx.xx in a text box.

I have tried using the format function as
format(Total,###0.00) but that gives me results as xxx,xxx.xx which does not solve my problem. Pls guide asasp.

Thanks in advance

Regards

Apoorva

From:
Apoorva Gala
You can mail me at apoo1972@rediffmail.com
 
hi,

What if the number is larger (or smaller) than 9,99,999.99 ?

Well anyway your could do something like:
----------------------------------------------------------
Dim n As Long
Text1.Text = Format(Text1.Text, "0.00")
n = Len(Text1.Text)
If n > 6 Then Text1.Text = Left$(Text1.Text, n - 6) & "," & Right$(Text1.Text, 6)
If n > 8 Then Text1.Text = Left$(Text1.Text, n - 8) & "," & Right$(Text1.Text, 9)
---------------------------------------------------------- Sunaj
'The gap between theory and practice is not as wide in theory as it is in practice'
 
Try this:
Format$("123456.78","#0\,00\,000\.00")

or

Format$(123456.78,"0\,00\,000\.00#")

but NOT

Format$(123456.78,"#0\,00\,000\.00#")

Make sure that if the # is used on the left or right side only, and not both - if the number to be formated can have an unlimited number of decimal whole number places. In that case I would use the last one but round the number first:

Format$(Round(123456.78),"#0\,00\,000\.00")

Note: This will not work for certain international number formats - in the cases where the decimal seperator is a comma instaed of a dot, another approach will need to be taken.
 
Hey BBG Thanks but that is not that I was looking for.
I tried yr idea but it is hardcoded for that big value what if value is small ?

What I am looking for is as below.

If the amount is 100 it should give as 100.00
If the amount is 1000 it should give as 1,000.00
If the amount is 10000 it should give as 10,000.00
If the amount is 100000 it should give as 1,00,000.00
if the amount is 1000000 it should give as 10,00,000.00

means amount is variable.

Thanks again
Apoorva From:
Apoorva Gala
You can mail me at apoo1972@rediffmail.com
 
It is truely a weird formating, but my code would work that way.
If your use it in more than one place make it into a function.

Sunaj
'The gap between theory and practice is not as wide in theory as it is in practice'
 
Hey Sunaj ,

Sure I will try yr code.
And I will get back to you later .

Thanks for replying

Apoorva
From:
Apoorva Gala
You can mail me at apoo1972@rediffmail.com
 
If you are getting the value for the text box from an Access query, you could format the field in the Access query.

If the unformatted value is say "V", add a field for the formatted value "FV" to be FV:Format(["#.000]} in the access query.

brian
 
In that case you could do this:

myString = Replace(Format$(myNumber, "#\,##\,##0.00"), ",,", vbNullString)
If Left$(myString, 1) = "," Then myString = Right$(myString, Len(myString) - 1)
 

If you are using Access, then the Replace function in my code example will not work, as there is no replace function in Access (at least in Acc '97.)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top