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

TextBox with first character uppercase

Status
Not open for further replies.

MontyItaly

Programmer
Feb 5, 2013
23
IT
In a normal TextBox I use InputMask "!XXXXXXX" for a field of 8 characters (First upper others lower).
In the fields of 30, 40 characters, Can I not use '! XXX .....' 40 times?.
Make a function or use MaxLengh or use NODEFAULT...

Thanks
Monty
 
Inputmask is not the only thing you can use. How about This.Value = Proper(This.Value) in interactive change?

Bye, Olaf.
 
Thank Olaf

I did not know Proper(), very interesting. But if I use This.Value = Proper(This.Value) in interactive change the cursor remains on the first character, if I put KEYBOARD '{END}' in interactive change does not create the space. Or something wrong?
Can I use Proper() in Valid of the field.
 

You could specify Maxlength 40 and and Format !

 
mm0000 I would like only first uppercase "Italy" not "ITALY
 
Of course you can also use Proper in the valid, yes. That's perhaps the easiest solution.
You could also use !XXX... as you intended. Just make it "!"+REPLICATE("X",LEN(field)-1) for example.

Bye, Olaf.
 
Olaf, where do I put
"!"+REPLICATE("X",LEN(field)-1)
in Init of Form?

THISFORM.TextBox1.InputMask = "!"+REPLICATE("X",LEN(field)-1)

Monty
 
Monty,

My preference would be to put that code in the Init of the textbox, and to modify it as follows:
Code:
THIS.InputMask = "!"+REPLICATE("X",LEN(field)-1)

The advantage is that it will make the textbox generic and self-contained. If you put it in the Init of the form, you are introducing an unnecessary dependency, plus you would have to modify the Init every time you add or remove a textbox.

Mike



__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Right Mike better in Init of the testbox!
even though I have more than 50 years I still have to learn a lot!

Monty
 
Comic proposal to change the name to the forum...
A group of "desperate people" asking for help to Olaf and Mike

;-);-);-);-);-);-)
Monty
 
even though I have more than 50 years I still have to learn a lot!

Ah, you are one of the younger fellows.

A group of "desperate people" asking for help to Olaf and Mike

I would rather say Olaf and his faithful helpers.

Mike





__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Thanks for finishing the job, Mike. You're a good helper [wink].

Of course you also need to change the field name for the LEN(field) part to work, or insert the number of X you want. You don't need the code at all, if you manually set the Inputmask, of course. Len(field) is possible for char fields only. With Memo or Varchar fields you get variable length, but Memos and textboxes don't go well anyway.

It would be more generic to use Len(Eval(This.ControlSource)) instead of Len(field), which depends on the controlsource, of course. Just ensure the table is open, when you evaluate the field length. FISZE() is another possibility, but I circumvent it, as it can mean file size or field size, depending on COMPATIBLE mode ON or OFF.

Also you could combine U and W as in U which does upper the first letter and lowers all others, it also only allows letters as input. You'd have to check if that includes spaces at least, otherwise that might be too restrictive.

Bye, Olaf.
 
Ok Olaf, You anticipated my next question with "Len(Eval(This.ControlSource))"
So if upper the first letter
THIS.InputMask = "!"+REPLICATE("X",Len(Eval(This.ControlSource))-1)
if all lowers
THIS.InputMask = REPLICATE("X",Len(Eval(This.ControlSource)))
for all character TextBox with a field in ControSource.

Thank a lot

Monty
 
X is allowing any char, upper or lower. If you want to enforce lower, use W, upper letters can also be enforeced by U instead of !

Bye, Olaf.
 
I work with VFP 8.0 and there are no 'W' and 'U', but I prefer 'X' and '!'
For example my users input "Castel San Pietro Terme" or "Sant'Agata sul Santerno" or
"Via Garibaldi, 11/m". All combinations...

Monty
 
To normalise such inputs is not only a question of that kind of Inputmask. A single ! only uppers the first letter of the whole field, not of each word, that should be clear. Proper of course fails on "sul" and with names it's incorrect with "McMillan" or "O'Neil" or such things. So if you want to match city names, you should match them all lowercase and have the correct writing in a database.

Bye, Olaf.
 
You might want to look at
True PROPER Command faq184-4320

I haven't used it myself, but it looks as though if you made use of the TrueProper() function shown there instead of the native VFP Proper() you might be able to overcome some of the more unusual situations like O'Neil, McDermott, etc.

Good Luck,
JRB-Bldr
 
jrbbldr TrueProper() function is very interesting, must be adapted to the Italian language.

Thank
Monty
 
Hi Monty

I use the following to make proper each word in caps whatever the length is:

Code:
*TextBox.InteractiveChange
LOCAL nSelStart
nSelStart=this.SelStart 
this.Value=PROPER(this.Value)
this.SelStart=m.nSelStart

Thanks

Saif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top