|
Post by Binary1248 on Jun 7, 2020 0:34:41 GMT
Should not this program loop until a key is pressed ? WARNING, this seems to get in an infinite loop with no way to exit the program except invoke windows task manager. I am using Liberty Basic V4.5.1
'test Prgm ExitKey
'Wait for key press
for i = 1 to 10
print I 'just some junk to see live screen
next i
do while a$="" 'loop till something in a$
a$= inkey$
loop
'
print a$
print "What do we put here to exit to Windows ?"
end
|
|
|
Post by B+ on Jun 7, 2020 0:44:15 GMT
INKEY$ is meant for Windows not console or main Window see Help
You might like this:
'accept characters and display them until Enter is pressed text$ = "" while c$ <> chr$(13) c$ = input$(1) print c$; if c$ <> chr$(13) then text$ = text$ + c$ wend print "You typed:"; text$ end
|
|
|
Post by Binary1248 on Jun 7, 2020 1:23:59 GMT
Thanks B+, that will work perfect in my existing code. Now is there a way to exit the basic program back to Windows, currently I tell the user to click on the exit box in the upper right corner. This is in the exe program (compiled). I'll compile your program and do some testing. Paul
|
|
|
Post by Binary1248 on Jun 7, 2020 1:27:02 GMT
Well, it does exactly what I want when compiled to an EXE program. Will play around some more then add to my program Paul
|
|
|
Post by Rod on Jun 7, 2020 7:02:22 GMT
The loop was just looping. Nowhere did you scan or wait for input. So inkey$ never got acted on. To exit to Windows call your quit routine and END or simply close all resources where you are and then issue the END statement. The input$() statement stops and reads the keyboard queue and does not need scan or wait.
|
|
|
Post by Binary1248 on Jun 7, 2020 17:15:30 GMT
B+ program works perfect by itself, exits back to windows when "cr" is pressed. But when added to my program, it does not exit back to windows, I still have to click on the x in upper right corner to close back to windows. "close all resources where you are" strikes a question in me, but I don't have any that I know of. Tried the statement "close" but that just creates an error. Have some simple one dimensional tables, but "close" belches when I try to close a table. Should I post the code listing ? It is somewhat clumsy right now.
EDIT: This question about exiting back to windows applies only to the complied EXE file.
2nd EDIT: I am striping out parts of my program to find where it changes the exit problem, so far table$ creations don't seem to be a problem. 3rd EDIT: Oh confusion. After stripping out all code and then replacing section by section, it now works with the expected exit to windows, just need to compare the listings and see what's different to cause my problem.
|
|
|
Post by Rod on Jun 7, 2020 18:38:43 GMT
You need to close resources you have opened like windows And files, anything that gets a #name
|
|
|
Post by B+ on Jun 7, 2020 18:53:00 GMT
You need to close resources you have opened like windows And files, anything that gets a #name and if you have nothing to close, END should do it. SCAN helps make the top red X work in loops.
|
|
|
Post by Rod on Jun 7, 2020 19:06:57 GMT
The program can perform countless loops very very fast. Only a few commands look outside the loop for instruction or interrupt. Scan checks for outstanding events. Wait hangs about for the next event. An event is created by keyboard or mouse or timer activity. So you create events and you respond to them. It’s all very interactive. You need event handlers established to catch your interrupts. Buttons and controls have built in interrupts, graphic boxes can create their own.
|
|
|
Post by Binary1248 on Jun 7, 2020 21:59:33 GMT
Well, I had a call to a subrtn within a subrtn. It was for diagnostic and not needed for the program. When commented out, the EXE program now exits properly. So a sub within a sub (nested subs ?) not allowed. The subs are all "end sub" returned befor the end of the program and exiting. Need to test more simpler setups to see if this is true. The simple run from Basic without compiling does not complain about nested subs, and the EXE program works with nested sub, but won't exit to windows on "CR".. My problem is not that the program doesn't work in either case, my stupid brain keeps saying "WHY ?)… First I need to go to HELP and see if it discusses how deep nested subs can go. Paul EDIT: Well, B+ program works and exits to windows with a dbl nested call. So I am going to set this aside for awhile and just work on the main purpose of the program for now.
|
|
|
Post by cundo on Jun 7, 2020 22:46:24 GMT
The mainwin will not close when debugging. Is that what you mean?
|
|
|
Post by B+ on Jun 7, 2020 23:47:41 GMT
The mainwin will not close when debugging. Is that what you mean? I do get the impression it is just mainwin so far, which is why INKEY$ won't work
BTW that snippet of code came from Help for INPUT$(1) the function.
|
|
|
Post by Binary1248 on Jun 8, 2020 3:25:40 GMT
It is just a relatively simple program that flips characters around in some tables. It does not have any graphics or sub windows, only print statements. When I compile into an EXE program, then with the Liberty editor window closed, when I run the EXE program it may or may not exit into windows depending on the above description. The suggested code snippit by B+ example code works every time, even with several nested subrtn (CALLs). I am going to move the nested subrtn out of my program, maybe work on why this messes up later. Need to work on cleaning up my code so it is not so messy. My last Basic coding was in Visual Basic 6, and QB 4.5. So some (maybe many) differences. I also do a lot of coding in GC Basic that compiles into assy for PICS. Thus my difficulty at working with this new Basic, it is great but still some learning curve. Many thanks for your help all.
|
|
|
Post by Binary1248 on Jun 8, 2020 4:24:07 GMT
Well, it's late. I found the problem lies not in a 2nd level subrtn call, but the subrtn itself. It's late so I'll publish a simplified code list tomorrow. (A simplified code that works when the offending subrtn is patched out)
EDIT:Well wop di do, even dbl nested calls work with my timer rtn in simple test code. I need to go back and look really carefully at my original code and see if I can spot the diff.
|
|
|
Post by Binary1248 on Jun 9, 2020 17:52:08 GMT
I have circumvented the problem by replacing the time delay subrtn with a simple looping within a loop delay. This allows exiting the program smoothly to windows. Listed below are the simple delay that works, and the delay program that I got from the LB help files, which works as a delay, but doesn't allow the program to exit to windows when finished. I do appreciate the help from all. . . .Simple crappy delay but allows smooth exit to windows, it works and used only for some debug purposes. '------------------------------------------------------------------------------ 'Call this when you want a x ms delay in code for testing ' call with tmevar value, in ms sub timerx for i = 1 to tmevar for ijx= 1 to 1000 next ijx next i end sub
'---------------------------------------------------------------------- The following doesn't allow smooth exit to windows when program ends. '---------------------------------------------------------------------- 'Call this when you want a x ms delay in code for testing ' call with tmevar value, in ms sub timerx 'set a timer to fire in tmevar ms 'using branch label event handler timer tmevar, [exittime] wait 'wait here print "Should never see this print line" [exittime] 'the branch to label, now exit.
end sub
|
|