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!

Forcing UPPER case in a text box input string

Status
Not open for further replies.

Jerim65

Technical User
Aug 8, 2010
99
AU
I'm not sure whether I've ever known how to do this - I would appreciate any help.

Coldan
 
You want to look at the textbox's FORMAT property (You should also look at the InputMask for more options.)

If you know the max characters say 5 then the format properrt would be "!!!!!" e,g, each ! means one character forced to upper case. (Other non characters are still allows so "a123q" would be displayas as "A123Q")

Again look at the built-in help many options etc exist for FORMAT

Lion Crest Software Services
Anthony L. Testi
President
 
To find other options for both the INPUTMASK and FORMAT property look at your VFP Help file.

In your Command Window type:
HELP inputmask
or
HELP Format Property

Good Luck,
JRB-Bldr
 
Any code that you put into the Format property applies to the entire field so ! is enough here to make the whole string upper case - you don't need to worry about counting characters.

Codes in InputMask apply character by character. I'd only use this if I needed to apply something complex like A99-A99. InputMask also has U and W codes for more control.

Geoff Franklin
 
If you know the max characters say 5 then the format properrt would be "!!!!!" e,g, each ! means one character forced to upper case.

Just to clarify:

- The Format property applies to the whole field. So you only need one exclamation mark to capitalise the entire field.

- The InputMask works on a character-by-character basis. So, for example, X!X!XXX would capitalise the second and fourth characters only.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro tips, advice, training, consultancy
Custom software for your business
 
In the format property of the edit box I just added a ! - this didn't change the input chrs.

Maybe I misunderstand, or your answers don't really apply to what I was wanting.

I want to see UPPER case chrs as the user types into the box.

Maybe this isn't possible.

Thanks
Coldan

 
Coldan,
The thread says "Forcing UPPER case in a text box input string" TEXTBOX being the important word here. Your last posting says "In the format property of the edit box.." Note EDITBOX. Is it a Text or Edit box?

I say that because I have never tried to force upper case in an edit box. (I just did a quick test and the '!' did not work for me.) So maybe formating does not work with editboxs (anyone else know?) Assuming for a sec that the formating does not work one could caputue the keystrokes and force the uppercase by hand.

Bottom line can you be a little clearer with your request (Text vs Edit) and maybe someone can give you an EditBox solution if that is what is needed.


Lion Crest Software Services
Anthony L. Testi
President
 
Help says that only K and Z are valid formats for an edit box.

I think you're going to have to do this in code - you might be able to use SelStart to detect the position of the cursor in the edit box and then SubStr and Stuff to replace that character as it's being typed.

Geoff Franklin
 
YOU COULD DO CAPSLOCK(.T.) IN THE GOTFOCUS() EVENT OF THE EDITBOX AND YOU MAY SAVE CAPSLOCK() IN SOME PROPERTY TO TURN CAPSLOCK BACK TO WHAT IT WAS IN THE VALID() OR LOSTFOCUS() EVENT.

BUT WHO WANTS CAPS IN AN EDITBOX, ANYWAY? EDITBOXES ARE FOR TEXT AND TEXT IS MUCH BETTER READABLE IN MIXED OR LOWER CASE!

ONE CATCH: USERS COULD TURN OFF CAPSLOCK, SO YOU'D NEED TO TURN IT ON AGAIN IN INTERACTIVECHANGE.

AND A SECOND IDEA: USE THE KEYPRESSEVENT AND SUPPRESS LOWER CASE LETTERS BY NODEFAULT AND USE THE KEYBOARD COMMAND TO SEND AN UPPER CASE LETTER FOR EACH SUPPRESSED LOWER CASE LETTER.

Bye, Olaf.
 
Olaf makes a good point.

But, if you really want to force an edit box to be all caps, I would use the KeyPress event, like this:

Code:
IF BETWEEN(nKeyCode, 97, 122)
  NODEFAULT 
  KEYBOARD CHR(nKeyCode - 32)
ENDIF


Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro tips, advice, training, consultancy
Custom software for your business
 
Thanks for the above discussion - I do want caps in the text entry area so I will try Mike's and Olaf's sugestion when I get back to that app.

Many thanks

Coldan
 
Yes Dave, but in the case of long texts this can get sluggish. Actually it's better in one way, as it can also cope with text copied into the editbox with lower case letters.

Finally using UPPER() on the editbox value or the bound table field right before saving is the safest solution to only store upper case text.

Bye, Olaf.
 
using UPPER() on the editbox value or the bound table field right before saving is the safest solution to only store upper case text.

Agreed. But then the user doesn't see the upper case while they typing. But maybe that doesn't matter.

Coldan, it would be nice to know a bit more about why you ae doing this. What is it about this particular edit box that requires the text to be capitalised?

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro tips, advice, training, consultancy
Custom software for your business
 
Hi Mike,

This is just an 'idea' of mine for one of my apps. The editbox is for a user to type in the name he/she wants to use for a new table that is to be created in my application.

Using upper case

1 Enables the new tables to 'stand out' visually in the selection area in the 3rd party application.

2 I want them to SEE what is happening. ( rather than post processing)as they will have to find it later.

3 I was curious as to how to do it (as I am with many of my other questions).

Regards

Coldan

 
Coldan,

When it comes to filenames, I agree that i'ts useful to display them in upper case. I do the same in my own apps (but I never use an edit box for that).

If you're sure you want an edit box (rather than a text box), I'd suggest you go with Dave's solution, that is, putting This.Value = UPPER(this.Value) in the InteractiveChange.

This will be slightly slower than my suggestion (see my second post, above [24 Nov 10 4:13]), but will have the advantage that it also capitalises text pasted from the clipboard. I wouldn't worry about the slowness. It's unlikely that a user will be typing so fast to make it an issue.

Give it a try.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro tips, advice, training, consultancy
Custom software for your business
 
If you want a filename in upper case then you could use the PutFile() function instead. This asks the user to select a directory and enter a filename and it returns the full name and path in upper case. Use JustFName() and JustPath if you need to separate name and path.

Geoff Franklin
 
I agree with Geoff,

you either use PutFile() or GetFile() depending on creating a new file or choosing an existing one, you could also use a Textbox with Format set to "!" and create a DBF of that name in the directory the user picks by GetDir().

You may also not want the user to decide freely where to create a DBF, but keep data together in a central directory. For multiuser environments in a file share and for single users somewhere within a folder of your application in their documents directory.

If you chose the Editbox, because you can bind it to a memo field, you could make an exception here and use an unbound textbox, the textbox control itself is not limited to 254 chars, it's only a limitation of char fields, so there is no need to use an editbox, because you save that full path filename in a memo field.

Bye, Olaf.
 
Hi Guys,

1 I have used an Editbox on my form - possibly due to my 'learner' status which has been ongoing for a few years <G>.

2 A file selector function is not a possibility because this name has to be used to rename a table I create in my program and allow the user to determine how the table will be named when it is used in the 3rd party app - hence the 'standing out' of an uppercase table name.

3 I have implemented Daves's solution in Interactive Change and it works exactly how I want.

Thanks to all of you for your patience and explanations.

Regards

Coldan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top