|
Post by lester34 on Dec 2, 2018 15:21:55 GMT -5
QB 4.5 had this code:
DO k4$=inkey$ LOOP while k4$=""
How do I do this in LB?
|
|
|
Post by tsh73 on Dec 3, 2018 1:36:49 GMT -5
I'm afraid you can't do *just that*
LB console mode designed more for debugging stuff so it has no non-blocking inkey.
Liberty basic way would be to add a GUI, and control loop via GUI control (checkbox etc).
EDIT but that really make your program flow change. For example if you do "busy loop" - your program will not response to GUI. You have to use timer or SCAN Some example. If checkbox is set, it does some stuff - then waits till 1 second passes - then repeats (so actually '[main.inputLoop]' gets jumped on every 1000 ms) nomainwin
WindowWidth = 248 WindowHeight = 435
checkbox #main.checkbox1, "Clear this checkbox to stop", [checkbox1Set], [checkbox1Reset], 26, 16, 232, 20 texteditor #main.textedit2, 22, 46, 208, 315 open "loop by checkbox" for window as #main print #main, "trapclose [quit]" print #main, "font ms_sans_serif 0 16" print #main.checkbox1, "set"
isLoop=1 i=0 timer 1000, [main.inputLoop] 'wait
[main.inputLoop] 'wait here for input event if not(isLoop) then wait 'else do stuff for j = 1 to 10 i = i+1 print #main.textedit2, i next print #main.textedit2, time$()
wait
[checkbox1Set] 'Perform action for the checkbox named 'checkbox1' isLoop=1 wait
[checkbox1Reset] 'Perform action for the checkbox named 'checkbox1' isLoop=0 wait
goto [main.inputLoop]
[quit] timer 0 close #main
|
|
|
Post by Gordon Rahman on Dec 3, 2018 19:22:32 GMT -5
QB 4.5 had this code: DO k4$=inkey$ LOOP while k4$="" How do I do this in LB? DO
k4$=input$(1)
scan
LOOP while k4$=""
print k4$
wait
I really agree with tsh. LibertyBASIC is meant for Windows ..... but of course you can still use QB4.5 Gordon
|
|
|
Post by tsh73 on Dec 4, 2018 3:22:08 GMT -5
Gordon, inkey$ in QB is non-blocking - program runs until something is pressed input$(1) in LB is blocking - program stays right here until key is pressed
So it will not work as asked.
|
|
|
Post by Gordon Rahman on Dec 4, 2018 12:31:51 GMT -5
In LB we could do it like:
'Open a graphic window 'or Open a graphicbox in a (regular) Window 'and set focus to that window or box
open "A graphic window" for graphics as #g #g "when characterInput [Keystroke]" #g "setfocus" wait
[Keystroke] I$ = Inkey$ print I$;
wait
In the console mode of LB:
DO k4$=input$(1) LOOP while k4$="" print "key ;k4$; wait
gives a one time walking throu the DO LOOP result as tsh73 pointed out
|
|