
Formatting Numbers in a Textbox/Richtextbox
Hello. I am reworking a currency translator (small program) whose function
is to convert US dollars to several European currencies. This was a class
assignment in beginning VB, and was written in v. 4. I am using v. 5 to
play with it now, and update and add features. One feature I'm adding is
the ability to update the exchange rate at run time.
I would like the user to enter digits into a textbox control, up to 4 or 5
or 6 depending on which currency & textbox, of them, so that there can be
up to 4 significant digits to the right of the decimal. One should not
have to type a decimal, the program will need to take whatever number is
entered and format it:
case 1 if the first digit is a 1 then the number will read 1.xxx
case other if the first digit is > 1 then the prog will format it
as .xxxx or xx.xxxx
depending on which text box it is entered into (each currency uses a
separate textbox so how it operates depends on which one is used).
Taking just case 1: if I enter 1234, then it should be formatted (upon the
event that does this*) as 1.234. I have tried using a custom format:
textbox1.text = format(textbox1.format,"0.###") and a lot of other
formatting directions, but the result is invariably something like:
123.4 or 12.34 or 1234. Other attempts at the format code:
"#.000"
"#.###"
"0.##0"
etc. I just can't seem to find the one which will guarantee using 3 of the
numbers to the right of the decimal. (The textbox has a property that
allows limiting the number of places typed in, so that I can limit this to
4. Error checking routine can ensure that the first digit allowed in the
the case 1 textbox is a '1', etc. But I can't get the formatting to work.)
* the event is either textbox1.lostfocus or command1.onclick
Anyone? Thanks, /ts
/ts