[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

Using Commas reversing the order

Posted on 2000-02-07
6
Medium Priority
?
213 Views
Last Modified: 2010-05-02
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
0
Comment
Question by:johnmhat
  • 3
  • 2
6 Comments
 
LVL 2

Expert Comment

by:p_biggelaar
ID: 2496705
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.
0
 
LVL 10

Expert Comment

by:caraf_g
ID: 2496800
"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)
0
 

Author Comment

by:johnmhat
ID: 2501821
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....
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
LVL 2

Accepted Solution

by:
p_biggelaar earned 200 total points
ID: 2501887
Okay, so it seems you're using the format command during the Change event. In that case you should try and add the following line to your code:

text1.SelStart=Len(text1.Text)

If I'm wrong about where you put you're code, please tell me exactly what you do and when
0
 

Author Comment

by:johnmhat
ID: 2502194
Thank you very much!  I am still new at this, what does that line of code do exactly....
0
 
LVL 2

Expert Comment

by:p_biggelaar
ID: 2503231
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...
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

590 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