Page 1 of 1

Forcing all capitals in a text field

Posted: Sun Dec 30, 2012 1:14 am
by ICCS_User
Can I I force all text in a field to be in all capitals?
Thanks!

iccs

Re: Forcing all capitals in a text field

Posted: Sun Dec 30, 2012 1:40 am
by sturgis
one way would be to use the toUpper function. (in the dictionary) you can either wait for all input to complete and then change everything to upper, do using key events (keydown, or rawkeydown) or you could have it run every time the text changes in the field in any way. (including delete, returns, backspaces) using on textChanged. Or you could do it on closefield

if you use keyDown here is a simple example (placed in the field script) that might do what you wish.

Code: Select all

on keyDown pKey
-- make sure its a letter
   if pKey is among the chars of "abcdefghijklmnopqrstuvwxyz" then
      put toUpper(pKey) into pKey -- force the key to upper.
      put pKey into the selection -- put it at the current insertion point
   else
      pass keydown -- otherwise just pass the key along as is. 
   end if
end keyDown

Re: Forcing all capitals in a text field

Posted: Sun Dec 30, 2012 2:41 am
by dunbarx
Sturgis.

Small point, and one I had to test myself, but only lower case letters are affected by this function.

The dictionary even says as much, which I read only after testing. Typical.

Craig

Re: Forcing all capitals in a text field

Posted: Sun Dec 30, 2012 4:31 am
by sturgis
Only reason its in an if statement is so that it doesn't needlessly run on anything but letters. Probably no discernable speed difference, but I figured 1 if check is (even if unnoticeably) faster than a function call and an insert into a field.

Is kinda pointless do do so trying to save unmeasurable time.

Re: Forcing all capitals in a text field

Posted: Sun Dec 30, 2012 7:36 am
by Simon
toUpper??
That has to be the worst LC command...wait no... good command, lousy notation.
charToUpper
caseToUpper
shiftCase
charShift
I could keep going with these :D
If there are LC beginners reading this, this is the only example I know of.

Simon

Re: Forcing all capitals in a text field

Posted: Sun Dec 30, 2012 3:16 pm
by ICCS_User
sturgis wrote:one way would be to use the toUpper function. (in the dictionary) you can either wait for all input to complete and then change everything to upper, do using key events (keydown, or rawkeydown) or you could have it run every time the text changes in the field in any way. (including delete, returns, backspaces) using on textChanged. Or you could do it on closefield

if you use keyDown here is a simple example (placed in the field script) that might do what you wish.

Code: Select all

on keyDown pKey
-- make sure its a letter
   if pKey is among the chars of "abcdefghijklmnopqrstuvwxyz" then
      put toUpper(pKey) into pKey -- force the key to upper.
      put pKey into the selection -- put it at the current insertion point
   else
      pass keydown -- otherwise just pass the key along as is. 
   end if
end keyDown
This works great! However, I have another silly question. I already have an existing keyDown script (on keyDown var) in this field. How do I deal with more than one on mouseDown scripts in one field?

Re: Forcing all capitals in a text field

Posted: Sun Dec 30, 2012 3:53 pm
by sturgis
Depending on what is in the keydown, you can probably combine the two. Want to post your script?

Also, as dunbar (craig) pointed out, my script could be turned into a 1 liner since its silly to use a conditional in this CASE. (pun intended)

Post your current script, and most likely toUpper can be incorporated. (if not there are other ways to get it done.)

Re: Forcing all capitals in a text field

Posted: Mon Dec 31, 2012 2:31 am
by jacque
Simon wrote:toUpper??
That has to be the worst LC command...wait no... good command, lousy notation.
On the other hand, that's the name of the same function in lots of languages, so many people will already know it. Besides SuperCard, it's in Java, Real Basic, C++, VB, and more. Same goes for toLower.

Re: Forcing all capitals in a text field

Posted: Mon Dec 31, 2012 4:32 pm
by ICCS_User
sturgis wrote:Depending on what is in the keydown, you can probably combine the two. Want to post your script?

Also, as dunbar (craig) pointed out, my script could be turned into a 1 liner since its silly to use a conditional in this CASE. (pun intended)

Post your current script, and most likely toUpper can be incorporated. (if not there are other ways to get it done.)
Here's my existing script:

local tData

on mouseenter
put fld "theData" into tData
end mouseenter

on keydown var
put var after me
if me is among the words of tData then
get lineOffset(me,tData)
put word 2 of line it of tData into fld "output"
end if
end keydown

Re: Forcing all capitals in a text field

Posted: Mon Dec 31, 2012 5:43 pm
by sturgis
ICCS_User wrote:Depending on what is in the keydown, you can probably combine the two. Want to post your script?

Also, as dunbar (craig) pointed out, my script could be turned into a 1 liner since its silly to use a conditional in this CASE. (pun intended)

Post your current script, and most likely toUpper can be incorporated. (if not there are other ways to get it done.)
Change your keydown as follows:

Code: Select all

local tData

on mouseenter
   put fld "theData" into tData
end mouseenter

on keydown var
   put toUpper(var) after me -- change this line to force the upper case.  
   if me is  among the words of tData then
      get lineOffset(me,tData)
      put word 2 of line it of tData into fld "output"
   end if
end keydown