The 'key-event:'function below nicely allows me to 'filter' the
keystrokes into my GUI. So far, no code experiment at the line whose
content (near the end) is:
if 3 > length? to-string face/data [inform dialog2]
successfully allows me to know the number of characters in the 'face'
(a text field) currently entered.
Either nothing happens, (the referenced dialog doesn't open) or there
will be a compile time error.
I include the whole script below since context can be important.
**********************************************************************
Rebol[]
key-event: func [face event] [
either event/type = 'key [
digit: to-string event/key
print switch/default digit [
"0" [event/key]
"1" [event/key]
"2" [event/key]
"3" [event/key]
"4" [event/key]
"5" [event/key]
"6" [event/key]
"7" [event/key]
"8" [event/key]
"9" [event/key]
"^-" [event/key]
"^~" [event/key]
"left" [event/key]
"right" [event/key]
] [inform dialog]
if 3 > length? to-string face/data [inform dialog2]
] []
event
]
dialog: layout [
backdrop effect [gradient 1x1 0.0.0 0.0.180]
h2 "Field size exceeded or invalid character entered:" red
h3 {There can be only two digits in each number window,
and there MUST be two digits.} yellow
h3 {The only other allowable keys are 'tab', 'shift/tab',} yellow
h3 {'left arrow' & 'right arrow' and the 'delete' key} yellow
button "O.K." [hide-popup]
]
dialog2: layout [
backdrop effect [gradient 1x1 0.0.0 0.0.180]
h2 "Field size exceeded:" red
h3 {There can be only two digits in each number window,
and there MUST be two digits.} yellow
button "O.K." [hide-popup]
]
data-form: layout [
size 512x480
backdrop blue
vh1 yellow "Lotto Numbers Checking Form"
box 460x4 168.168.168 across
vtext bold yellow "Enter the (5) winning two-digit numbers, (left
zero for single digits is required):"
return
num1: field with [size: 25x24]
num2: field with [size: 25x24]
num3: field with [size: 25x24]
num4: field with [size: 25x24]
num5: field with [size: 25x24]
return
box 460x4 168.168.168 across
return
vtext bold yellow "Enter the wild card number, (left zero for
single digits is required):"
return
wc: field with [size: 25x24]
return
vtext bold yellow "Press Enter to check above entry against
database of held tickets:"
return
box 460x4 168.168.168 across
return
pad 30
indent 110
button "Enter" [chk-nbrs]
button "Clear" [clear-fields data-form show data-form]
]
chk-nbrs: does [
print ["....Checking existing database of existing tickets"]
]
main-face: system/view/screen-face/pane/1
insert-event-func :key-event
focus num1
view data-form