|
REM Determine if a InputD control contains a valid date
REM Obtain the instance of the BBjAPI object
LET myAPI!=BBjAPI()
REM Open the SysGui device
SYSGUI=UNT
OPEN (SYSGUI)"X0"
REM Obtain the instance of the BBjSysGui object
LET mySysGui!=myAPI!.getSysGui()
REM Set addWindow param values
X=10
Y=10
WIDTH=200
HEIGHT=200
TITLE$="BBj Window"
REM Set the current context
mySysGui!.setContext(0)
REM Create a window
myWindow! = mySysGui!.addWindow(X,Y,WIDTH,HEIGHT,TITLE$,$00010002$)
REM Add another control to show the effect of not being able to
REM move away from the INPUTD
myButton! = myWindow!.addButton(100,50,60,90,30,"Valid?",$$)
REM Add an InputD control that uses the current default mask, inserting
REM today's date when the user hits the restore key (normally ESCAPE)
myInputD! = myWindow!.addInputD(101,50,100,90,30,$080c$,"",$$,0,0)
REM When defining custom input rules, it may be useful to increase
REM to maximum input length of the control.
myInputD!.setLength(32)
REM Register the CALLBACK routines
CALLBACK(ON_BUTTON_PUSH,isValid,mySysGui!.getContext(),myButton!.getID())
CALLBACK(ON_LOST_FOCUS,validate,mySysGui!.getContext(),myInputD!.getID())
CALLBACK(ON_CLOSE,APP_CLOSE,mySysGui!.getContext())
REM Process Events
PROCESS_EVENTS
REM Callback routine called when the user closes the application window
APP_CLOSE:
RELEASE
RETURN
validate:
if myInputD!.isValid() then return
text$ = cvs(myInputD!.getText(),7)
if text$="ME" then gosub setMonthEnd
return
setMonthEnd:
today = jul(0,0,0)
y = num(date(today:"%Y"))
m = num(date(today:"%M"))
for d=28 to 30
me = jul(y,m,d+1,err=*break)
next d
myInputD!.setValue(jul(y,m,d))
return
isValid:
msg$ = myInputD!.getText()
msg$ = msg$ + iff(myInputD!.isValid()," is "," is not")
msg$ = msg$+" a valid date"
i = msgbox(msg$)
RETURN
|