Formatting Numbers in a Textbox/Richtextbox 
Author Message
 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



Thu, 27 Dec 2001 03:00:00 GMT  
 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



Thu, 27 Dec 2001 03:00:00 GMT  
 Formatting Numbers in a Textbox/Richtextbox
I just think that you are going to totally confuse your user . . . and why
not, Bill Gate$ has totally confused most of us - and people still keep on
giving him money ;-)  Formatting is for . . . well . . . formatting! What
you want to do is to insert a decimal point into a number which did not
previously contain one. You could do a lot worse (and probably a lot better)
than:

Text1 = Format(Left(Text1, 1) & "." + Mid(Text1, 2), "0.000")

Mike


Quote:
> 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


Fri, 28 Dec 2001 03:00:00 GMT  
 Formatting Numbers in a Textbox/Richtextbox
It was: Mon, 12 Jul 1999 02:06:09 +0100 and with STARTLING insight,  ""Mike

in a Textbox/Richtextbox" to "comp.lang.basic.visual.misc" :

-->I just think that you are going to totally confuse your user . . . and why
-->not, Bill Gate$ has totally confused most of us - and people still keep on
-->giving him money ;-)  Formatting is for . . . well . . . formatting! What
-->you want to do is to insert a decimal point into a number which did not
-->previously contain one. You could do a lot worse (and probably a lot better)
-->than:
-->
-->Text1 = Format(Left(Text1, 1) & "." + Mid(Text1, 2), "0.000")
-->
-->Mike

The final code, with error check:

If Mid(RichTextBox1(0).Text, 2, 1) <> "." Then
  RichTextBox1(0).Text = Format(Left(RichTextBox1(0).Text, 1) & "." +
Mid(RichTextBox1(0).Text, 2), "0.000")
End If
rateP = Val(RichTextBox1(0).Text)

And that worked 100%!  Thanks a lot.  I had no experience working with left
and mid functions.  Largely this is a self derived learning excercise.  I
think I've learned a lot!  Guess it might confuse a user, or not:  depends
on the clarity of the interface's presentation.  I was trying to do a bunch
of things automatically.  Whenever you have to enter a number into a
program, where possible the program ought to verify that the number is
useful for the calculation.  Sort of like making an icon and having to  put
in a valid path to a working directory or the process stops till you do.  

The code above will now allow input of up to 4 digits (limit placed by
textbox property) and verify that the decimal is in position two; if not,
it puts one there then calculates.  Voila.  

"Come to think of it, there are already a million monkeys on a million
 typewriters, and Usenet is NOTHING like Shakespeare." Blair Houghton
***********entia non sunt multiplicanda praeter necessitate***********



Fri, 28 Dec 2001 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. from Microsoft format Number to IEE format Number

2. Format phone number inside textbox control

3. HELP Formatting TextBox for whole numbers

4. number formatting in a textbox

5. formatting numbers in textboxes

6. Guarantee Number Formatting in a Textbox?

7. Format Numbers in VB Textbox

8. formatting numbers in textboxes

9. Validate and Format Currency Numbers in Textbox

10. Formatting Unformated Numbers in Word to Specific Formats?

11. How to convert number format to date format

12. WISHLIST: New event for Textbox/Richtextbox

 

 
Powered by phpBB® Forum Software