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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Format a textbox to currency on a form

Status
Not open for further replies.

VBFOXDEV35

Programmer
Mar 26, 2001
77
US
Hello all, This is a real easy questions I am sure you all can answer quickly. I am so used to VB here you can format a textbox to be numeric, but how to you in VFP 7.0?

My user will enter a value to the textbox, 15242.95, but I want to display to the user $15,242.95 when the focus leaves, but write to the database 15242.95. What is the easiest way to do this.

use the lost focus event to format the number to $15,242.95 when focus is lost and then write to the database the .text value (which I assume is 15242.95, whereas the .value will be the whole formatted expression).

Thanks all for your help.
Art
 
User the Format property of the texbox and put " $" (without the quotes)
 
Already tried using a "$" in the format of the textbox and I still just get numbers as if they were characters. I have been looking at the TRANSFORM() but I need to also have "," for format properly. I tried setting the separator, but no luck.

Any other idea?

Art Art DeGaetano II
Software Developer, MOUS
 
The textbox has to bound to a numeric field.

I create a form and in the load I put:
create cursor myCursor (dollars n(10,2))
go bottom
append blank

And put a textbox on the form. Set the ControlSource to myCursor.dollars
Set the Format to $
And that's it.

 
Cool, that I do understand, but what if you do not want the textbox to be bound to a field in a database? I guess I will have to create a number function to return the numeric expression with its associated picture string. Thanks anyway for the help.

Art

P.S. If you want I can let you all know how i did it. Art DeGaetano II
Software Developer, MOUS
 
ClayTech

As I suggested, just use a dummy cursor as a template for your input box. It get destroyed when the form is released.
 
Set your textbox properties to these:

Format: $K
InputMask: 999,999.99
Value: 0

The $ will include a dollar sign in the display. Setting the textbox's value to 0 will force it to be numeric type, although it can still be set to character type if you key in a string. The InputMask prevents anything but numbers, so this shouldn't happen. However, the best way to make absolutely sure it will be numeric is to bind the control to a numeric table field.

Ian
 
Ian, thanks for that little snip-it. I like that one better than the function I am using to convert the data. Thanks again to all of you who helped me on this today.

Art
Art DeGaetano II
Software Developer, MOUS
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top