Liberty BASIC Help Online |
SCAN
Description:
The SCAN statement causes Liberty BASIC to stop what it is doing for a moment and process Windows keyboard and mouse messages. This is useful for any kind of routine that needs to run continuously but which still needs to process button clicks and other actions. In this way, SCAN can be used as an INPUT statement that doesn't stop and wait.
Example:
'scan example - digital clock
nomainwin
WindowWidth = 120
WindowHeight = 95
statictext #clock.time, "xx:xx:xx", 15, 10, 90, 20
button #clock.12hour, "12 Hour", [twelveHour], UL,_
15, 40, 40, 20
button #clock.24hour, "24 Hour", [twentyfourHour], UL,_
60, 40, 40, 20
open "Clock" for window_nf as #clock
print #clock, "trapclose [quit]"
print #clock.time, "!font courier_new 8 15"
print #clock.12hour, "!font ariel 5 11"
print #clock.24hour, "!font ariel 5 11"
goto [twelveHour]
[timeLoop]
if time$ <> time$() then
time$ = time$()
gosub [formatTime]
print #clock.time, formattedTime$
end if
scan 'check for user input
goto [timeLoop]
[formatTime]
hours = val(left$(time$, 2))
if twelveHourFormat = 1 then
if hours > 12 then
hours = hours - 12
suffix$ = " PM"
else
if hours = 0 then hours = 12
suffix$ = " AM"
end if
else
suffix$ = ""
end if
formattedTime$ = prefix$+right$("0"+str$(hours), 2)
formattedTime$ = formattedTime$+mid$(time$, 3)+suffix$
return
[twelveHour] 'set up twelve-hour mode
twelveHourFormat = 1
time$ = ""
prefix$ = ""
goto [timeLoop]
[twentyfourHour] 'set up twentyfour-hour mode
twelveHourFormat = 0
time$ = ""
prefix$ = " "
goto [timeLoop]
[quit] 'exit our clock
close #clock
end
Copyright (C) 2003 Shoptalk Systems
Liberty BASIC - http://www.libertybasic.com/