Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Determine Significant Trailing Spaces in controls
Message
From
02/08/2007 11:42:44
 
 
To
02/08/2007 11:24:01
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 9 SP1
OS:
Windows XP SP2
Miscellaneous
Thread ID:
01245320
Message ID:
01245513
Views:
26
>>>I have a need to determine if trailing spaces have been entered into a textbox or a combobox by the user. If the user adds trailing spaces, then these are significant and part of the text expression. Normally the .Value property (or .DisplayValue) has the text padded with spaces to the full size allowed. I only want trailing spaces if they are entered by the user.
>>>
>>>I know I can trap the keystrokes and increment a counter if a SPACE is entered (reset if any other character entered), But I wonder if anyone has already "invented" this and has a ready solution. Thanks.
>>
>>Use Fontname='Foxfont' for the textbox
>>
>>Gotfocus: this.value=chrtran(this.value,chr(32),chr(176))
>>
>>Now you can compare this.value, all chr(32) are entered by the user, chr(176) already was there.
>
>Not sure how using Foxfont will help -- it gives a fixed width only. On the gotfocus, the value property has the full padding of spaces. The padding of spaces is controlled by the allowed size; a fixed width foxfont would only set the allowed length: lets say the allowed length is 20 chars; if the user enters the text SEARCH__ (8 chars, where the last two underscores represent spaces), when it is queried by the gotfocus, it would return SEARCH______________ (20 chars, with 14 spaces). How to know that two entered by user? Once the focus is lost from the control (even in the Valid event) the padding occurs of the spaces. So how to intercept?

The important thing is not the font, but what chr(176) shows, namely a greyish background. So if you wantt to start with an empty string, let the empty string not be empty, but a sring of only chr(176)s, like repl(chr(176),20). When the user has finished typing in, you end up with a string which contain the entered text, the entered spaces and a lot of chr(176)s. So it is very simple to get EXACTLY what the customers have entered, namely chrtran(txtInput.value,chr(176),'').

I have used this technique many times, it's very elegant and easy to implement. However, in order to also let the user use backspace correctly, I start with a loooong string, like repl(chr(176),1000). Then the user must really struggle hard to fool your code.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform