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

Numeric data entry from right to left 2

Status
Not open for further replies.

SitesMasstec

Programmer
Sep 26, 2010
508
Brasil
Hello colleagues!

I have a text box for inputing a currency value, for example 1234.95

When I use any calculator the numbers are displayed from right to left:
[pre]
1
12
123
1234
1234.
1234.9
1234.95
[/pre]
Is it possible to have the same behavior in a text box in VFP?


Thank you,
SitesMasstec
 
Do you own a copy of 1001 Things You Wanted to Know about Visual FoxPro (aka KiloFox)? If so, you will find a complete calculator-style textbox which will do what you want - along with a discussion on why this style of data entry is so difficult in VFP.

This is on page 93 onwards. Unfortunately, the code is much too long for me to post it here, even leaving aside copyright issues.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Chris, I downloaded the file and will test it, thank you.

Yes, Mike, I have 1001 Things... and I have just opened in the page you directed me (this book, has been on of my bedside -indeed my desktop side also- in the last few months) as I am diving in a new project. I'll also take a look at the thread you advised. Thank you and Chris, both have helped me a lot.

Thank you,
SitesMasstec
 
Of course, Mike. As soon as I implement the solution, I will let you know.


Thank you,
SitesMasstec
 
Hello colleagues!

Well, first of all, thank you Chris and Mike, for showing me two solutions, for about entering values in a text box, the numbers appearing from right to left, as in calculators. I tested both and each solves the problem I presented (because I saw an old program in Visual Basic with this behaviour in text box, and would like to implement it in a VFP program).

But as my users are accustomed to enter numeric values in VFP text boxes (from Standard class library) I think better not to adopt the calculator mode for data entry in numeric text boxes. Instead, I changed the Properties for data entry, for a clearer data entry:
Format: 999,999.99
InputMask: 999999.99 (I wrongly used 999,999.99 in this property)

Of course may be some situations which I will have to use the calculator mode for data entry.


Thank you,
SitesMasstec
 
I have done this, as I mentioned in the post above:
Format: 999,999.99
InputMask: 999999.99

When I put a value (example: 12345.67) in the text box and click on another object the value in the former text box does NOT show 12,345.67 as defined in the Format property.

Even if I put this.Format="999,999.99" in the LostFocus procedure it shows 12345.67 (and not 12,345.67 as desired!).[sad]

Thank you,
SitesMasstec
 
No, [tt]this.Format="999,999.99"[/tt] won't work.

The Format property is a single character that affects the entire field. The InputMask property contains a series of characters that affect the individual characters in the field. So it's the InputMask that you need to set to "999,999.99" in the LostFocus, not the Format. Just leave the Format blank.

Mike



__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
When you want output = input set Format to R and for numeric input use a # for any character that should be able to be a digit or +/- sign.

I wonder why you experiment with these properties, the calculator style numeric textbox class should offer all you need.

Chriss
 
Yes, Mike, as you advised, it works now!

I have to put this.InputMask="999999.99" in the GotFocus procedure, just in case the user need to be back to that text box. So now it is fine!

So, the InputMask overlaps anything in the Format?


Thank you,
SitesMasstec
 
[quote='SitesMasstec]So, the InputMask overlaps anything in the Format?[/quote]

No, you still seem to interpret the Format property as the equivalent to an Outputmask, even though Mike Lewis already told you it is not. Never was and is not intended for that.
Mike Lewis said:
this.Format="999,999.99" won't work.

The Format property is a single character that affects the entire field.

That alone should tell you that the format property works completely different than an input mask, even without knowing which options you have.

Forget about Format, or set it to "R".

In general, don't assume what properties are for, and if you realize they don't work as you expect, how about reading up on them? Then you'd know what they mean and how they work. I realize there's the difficulty of language barrier, perhaps, but sticking to assumptions when you're informed they don't apply is surely not getting you forward at all.

Chriss
 
Good to see you have it working, SitesMastec.

It's not that the InputMask "overlaps" anything in the Format. The two properties serve different functions. Either or both can be applied to a given control. Your problem was that the characters 9, comma or full stop are not legitimate settings for Format. They do no harm, but they have no effect.

I don't blame you for being confused. It is a confusing topic. Even though I've been using these properties since the first version of VFP - and the equivalents for @SAY/GET in FoxPro 2.x - I still need to check the Help from time to time.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
SitesMasstec said:
as my users are accustomed to enter numeric values in VFP text boxes (from Standard class library) I think better not to adopt the calculator mode for data entry in numeric text boxes.
So you changed your mind. Or is it the difficulty to chenge existing textboxes to the new class.

The calculator mode is not the only mode in Rick Borups "Enhanced Numeric Textbox Class" it also has a "machine style" mode.

Besides, you can use this textbox class wherever you want and only there, you don't have to change every textbox, wehn you don't want to. So is your problem more the indecision about what to use? Then that's something I fear nobody here can help you with.

Besides all that, you don't have to set the Inputmask in the GotFocus event, you can set it in the form designer at design time and at run time it just works all the time, once it is set and you don't have to wait for the control to get focus to set the inputmask, nor do you need to remove it when the control loses focus. It makes no sense to do that.

Chriss
 
you don't have to set the Inputmask in the GotFocus event .... nor do you need to remove it when the control loses focus.

That's a good point. If you keep the mask in force the whole time, the formatting (the dot and the commas) will be visible while the user is entering data, but they do not have to be explicitly typed. Just type the digits as usual.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
I am still using the standard TextBox, and I am testing these options Mike and Chris presented. I have not dismissed them, I just want to undestand well how to apply them.

For now, for the standard TextBox I have set Format property to Z (yes, Mike, I had wrongly thought Format is like PICTURE '999..." in FoxPro DOS...).


Thank you,
SitesMasstec
 
SitesMasstec said:
I have set Format property to Z
The help says, mainly:
help said:
Displays the value as blank if it is 0,...

I that really helpful, is that what you need?

I advised to use R.
help said:
R
Displays the format mask for the text box that is specified in the InputMask property.

The mask formats data for easier entry and clearer display. For example, if the mask is 99-999, the number 12345 is displayed as 12-345 but is not stored as part of the data. Use only with Character or Numeric data.

This is what you want. Despite, that the inputmask is the more important property anyway, which is not the first time we say this.

Chriss
 
Besides this, the core thing Mike said in an older thread that was also linked to:

Mike Lewis said:
...it's not simple. The explanation of how it works takes up eight pages. As Andy and Marcia say:

Andy and Marcia said:
We set out to create a numeric text box, and discovered why none exists. It was HARD!


...It's just that it is a difficult problem to solve. Ideally, the behaviour you are looking for should have been built into VFP - it's not an unusual requirement - but that's all history now.

So, in short, use the classes you were pointed to, don't try to stick with the native Textbox and just some properties, especially if you still don't focus on what we point out. It takes a lot to get the numeric input in calculator style done and you better take what others already have finished instead of trying to get there on your own.

Chriss
 
Chris: After some days I give up (at least temporarily) using calculator style for numeric data entry in text box, for two reasons:
1) The textboxes classes from Level Extreme and Kilofox, I don't know why accepts only 123.45, if I enter 12345.67 they both presents 12,345.6 or ***,***.**.

I tried to understand the Kilofox class (CH04, yes there are 8 pages about its class...)

2) I used the VFP Standard Textbox class (not calculator style for numeric data entry), but I set its Format property to Z in the form, I am satisfied, because only when it GotFocus it presents the ImputMask property (999,999.99). And it is the same style I use in my programs, and it is better now because of using Format property = Z.

Thanks again for you and Mike for the valuable help you both provided me.


Thank you,
SitesMasstec
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top