Link to home
Start Free TrialLog in
Avatar of johnmhat
johnmhat

asked on

Using Commas reversing the order

I have a string of numbers that I want to denote by 1000's.  Ex. 123456789 would be 123,456,789....I have tried to use

text1.text = format(text1.text,"###,###,###") and I have also tried to use the formatnumber method but the string that gets returned ends up wit the numbers in some type of "wrapped" order..Ex. instead of 123,456,789....I get   895,671,234.......Please Advise
Avatar of p_biggelaar
p_biggelaar
Flag of Netherlands image

I tried these, and they all work for me:

CStr(Format(CDbl(Text1.Text), "#,##0.00"))

CStr(Format(CDbl(Text1.Text), "#,###"))

Format(Text1.Text, "#,###")

If you're code looks the same as mine, it could be because:
- someone has entered a value that's not correct (I don't know where your from, but in Holland we are quite used to use a '.' to denote 1000's and a ',' for a decimal 'point'. Even though I programmatically tell to use a comma, if the international settings are Dutch, it will show a '.' This way you'll get conversion errors.

Anyway it is a good idea to evaluate whether the string is numeric or not by throwing in the IsNumeric() function. If your string is not a valid number, it will return false. (Though it will return true also for strings like "12.9,09.98"

I've never experienced scrambled strings as a result of a format.
Avatar of caraf_g
caraf_g

"Though it will return true also for strings like "12.9,09.98""

I didn't believe you, but it's true. O dear. (In English locale, it will return True for 12,9.09,98)
Avatar of johnmhat

ASKER

Thanks but I have tried that code, and it does supply the commas but it still returns the numbers in a different order.

The order entered is 123456789 but the order that is displayed is

895,671,234

where 1234 are entered and then the comma is placed after the 1 then once the comma is placed the cursor is set to the beginning of the string and  once the 5 is enterd the number appears as
51,234 and so on until the number above is the final result...Ideally I would like the number to appear as
123,456,789 as entered....
ASKER CERTIFIED SOLUTION
Avatar of p_biggelaar
p_biggelaar
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you very much!  I am still new at this, what does that line of code do exactly....
Well, that line of code tells the cursor where to be. Say you've got a textbox called Text1 and in it is a line of text like 'hello'.

Some scenario's
text1.Selstart=0 -> the cursor is blinking at the beginning of the textbox, before the text

Text1.SelStart 3 -> the cursor is blinking after the third character

The line of code I gave you tries to figure out the length of the string in the textbox, and places the cursor at the end of the text.

Another property that you might like is the SelLength property. A statement like

Text1.SelStart=0
Text1.SelLength=Len(Text1.Text)

would select the entire text in your textbox.

Have fun...