RosettaCodeData/Task/GUI-component-interaction/Liberty-BASIC/gui-component-interaction-1...

57 lines
1.3 KiB
Plaintext

nomainwin
textbox #demo.val, 20, 50, 90, 24
button #demo.inc, "Increment", [btnIncrement], UL, 20, 90, 90, 24
button #demo.rnd, "Random", [btnRandom], UL, 20, 120, 90, 24
open "Rosetta Task: GUI component interaction" for window as #demo
#demo "trapclose [quit]"
validNum$ = "0123456789."
#demo.val 0
wait
[quit]
close #demo
end
[btnIncrement]
#demo.val "!contents? nVal$"
nVal$ = trim$(nVal$)
if left$(nVal$, 1) = "-" then
neg = 1
nVal$ = mid$(nVal$, 2)
else
neg = 0
end if
validNum = 1
nDecs = 0
for i = 1 to len(nVal$)
if instr(validNum$, mid$(nVal$, i, 1)) = 0 then
validNum = 0
end if
if mid$(nVal$, i, 1) = "." then
nDecs = nDecs + 1
end if
next i
if nDecs > 1 then
validNum = 0
end if
if neg = 1 then
nVal$ = "-";nVal$
end if
if validNum = 0 then
notice nVal$;" does not appear to be a valid number. " + _
"(Commas are not allowed.)"
else
nVal = val(nVal$)
nVal = nVal + 1
end if
#demo.val nVal
wait
[btnRandom]
confirm "Reset value to random number";yn$
if yn$ = "yes" then
nVal = int(rnd(1) * 100) + 1
#demo.val nVal
end if
wait