SCAN
Omschrijving:
Het SCAN statement laat Liberty BASIC even stoppen met datgene waar het mee bezig was
om even het toetsenbord en de muisberichten van Windows te verwerken.
Dit is nuttig bij de soort routines die onophoudelijk lopen maar waar nog gebruiker
events zoals knop klikken en andere acties moeten worden opgevangen en verwerkt.
Op deze wijze, kan SCAN als een INPUT statement worden gebruikt die niet ophoudt en wacht.
Voorbeeld:
'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