Database - functionality for front end application
Cubist at aol.com
Cubist at aol.com
Sun Nov 16 16:13:52 EST 2003
sez janschenkel at yahoo.com
>Try the following script instead :
>
>on keyDown pWhichKey
> if the length of me > 10 then beep
> else
> send "Capitalize" to me in 5 milliseconds
> pass keyDown
> end if
>end keyDown
>
>on Capitalize
> put the selectedChunk of me into tChunk
> put upper(me) into me
> select tChunk
>end Capitalize
>
>Beware that the above script doens't fix 'pasted'
>text, nor text that gets into your field via
>'drag-and-drop'. There are ways of handling that,
>however.
>Have a look at the Transcript Dictionary entries for
>the 'pasteKey' and 'dragDrop' messages.
Keep the Capitalize handler simple -- don't bother with exceptions.
Instead:
on keyDown pWhichKey
if the length of me > 10 then beep
else
send "Capitalize" to me in 5 milliseconds
pass keyDown
end if
end keyDown
on Capitalize
put upper(me) into me
send "Capitalize" to me in 200 milliseconds
end Capitalize
Since there's only one field that needs the capitalization and length
controls, you can get way with putting the "keyDown" and "Capitalize" handlers in
that specific field. But if you had multiple fields that need to be all-caps,
you might consider putting those handlers in the card or group or stack
script, as appropriate; that way, one handler would take care of every field, as
opposed to one handler *per* field. Of course, you would have to keep track of
which field you're capitalizing at any given time...
Okay, here's a thought. Let's say you have your database stuff in a group,
containing multiple data-entry fields; give each of these fields some custom
properties, like so...
CapVal -- allowable values: "UC" for UpperCase, or "LC" for LowerCase, or
"AT" for As Typed.
DataLen -- allowable values: Any positive integer.
...and put this into the stack script:
on openStack
-- do the usual setting-up stuff
send "DataCheck" to me in 1 millisecond
end openStack
on DataCheck
repeat with K1 = 1 to the number of fields
if the customKeys of field K1 do not include "CapVal" then next repeat
-- I've prolly messed up the syntax here, but you get the idea, right?
put me into Fred
-- first: take care of capitalization
if the CalVal of field K1 = "UC" then
put upper (Fred) into Fred
else if the CalVal of field K1 = "LC" then
put lower (Fred) into Fred
end if
-- next: take care of length issues
if the length of Fred > the DataLen of field K1 then
beep 2 times
put char 1 to DataLen of Fred into Fred
end if
-- if you wanted to perform other data-verification tasks
-- on multiple fields, put 'em here. note that if some of those
-- tasks impinge on each other (if, for example, you had
-- one operation that *increased* the length of a field,
-- that could impinge on length limits), you may have to be
-- careful about the order in which you do things
if Fred <> field K1 then put Fred into field K1
end repeat
send "DataCheck" to me in 200 milliseconds
end DataCheck
The above is a rough draft, strictly off-the-top-of-my-head, but hopefully
someone may find the concept useful...
More information about the use-livecode
mailing list