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

Entering numbers into text boxes... 2

Status
Not open for further replies.

GriffMG

Programmer
Mar 4, 2002
6,343
FR
I'm sure I'm the only one with this problem - but you never know... and if anyone else has already come up with the same thing - I'm sorry to repeat you!

When a user clicks into a text box with a numeric value (rather than using the keyboard to enter it) the 'select' function doesn't fire and sometime the numeric value the user meant to enter can be multiplied by 10 - dependant on where the cursor clicks to (if you follow me!).

This is because if the number they enter starts more than a space away from the period marker VFP automatically inserts an extra 0 to the left of it

Code:
i.e.

[  100 .00] becomes [ 1000.00] as the user exits the
text box.

Now, you can 'train' the users to avoid this - but today I had an Director of a clients company complaining about it when HE does data entry. There is only so much you can teach someone in that kind of exulted position, so I dreamt up this...

Put the following in the text boxes click event:

Code:
this.selstart = 0
this.sellength = 120  && a number much bigger than the size of any reasonable number!

Now, the text box mimics the action that would have been fired should the user have tabbed in!

Simple to do, and if ou leave the 'doubleclick' event alone the user can still 'edit' the text by double clicking!

HTH


Regards

Griff
Keep [Smile]ing
 
I like the tip.

Ali Koumaiha
TeknoSoft Inc
Farmington Hills, Michigan
 
Griff,

I'm sure I'm the only one with this problem

No way. It's plagued me (on and off) over the years.

The problem only seems to occur if there is a Format of InputMask set for the control. For that reason, I have code called from my GotFocus which removes the mask or format when the user is editing; it gets restored in the LostFocus.

But I'll give your method a try next time the issue comes up.

Mike


Mike Lewis
Edinburgh, Scotland

My Visual Foxpro web site: My Crystal Reports web site:
 
A simpler solution is to set SelectOnEntry to true and then in the click event add:

this.setfocus()

Works great!

Glenn
 
glennpd,

If I had some code in the setfocus() of my control would your idea cause it to run twice?

Guess either way you try and work around this problem you'd want to subclass the textbox baseclass and add this new functionality to it. That way you could use the subclass everywhere in your application where you wanted a numeric value displayed/edited. "clsNumericTxt" or something. I usually use subclasses of the main controls anyways, unless I am in a huge hurry to just mock something up.

Slighthaze = NULL
craig1442@mchsi.com
"Whom computers would destroy, they must first drive mad." - Anon​
 
this.setfocus()

Now that is rather neat!

And thanks for the star whoever gave me that!

Regards

Griff
Keep [Smile]ing
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top