Forcing all capitals in a text field
Posted: Sun Dec 30, 2012 1:14 am
Can I I force all text in a field to be in all capitals?
Thanks!
iccs
Thanks!
iccs
Questions and answers about the LiveCode platform.
https://www.forums.livecode.com/
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?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
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.Simon wrote:toUpper??
That has to be the worst LC command...wait no... good command, lousy notation.
Here's my existing script: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.)
Change your keydown as follows: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.)
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