|
Post by cryptomen on Jan 2, 2024 9:40:36 GMT -5
I can not trap quit button when I am listing a long list inside a text editor box texteditor #main.te, 0, 0, 790, 530 which started with:
open "Unbreakable Lister" for window as #main
How can I make it yield to service the quit signal while it is printing in a FOR NEXT loop with #main.te, SQ$;" ";AMT$;" ";DT$ pumping out a million records selected from a MySQL table?
#main, "trapclose sQuit"
#main.te, "!autoresize"; #main, "font fixedsys 10";
Shouldn't it jump to SUB sQuit when quit [X] button clicked?
|
|
|
Post by tsh73 on Jan 2, 2024 9:53:16 GMT -5
Insert SCAN in a loop. It will allow Windows to process messages such as window closing.
[setup.main.Window]
'-----Begin code for #main
nomainwin WindowWidth = 550 WindowHeight = 410 UpperLeftX=int((DisplayWidth-WindowWidth)/2) UpperLeftY=int((DisplayHeight-WindowHeight)/2)
'-----Begin GUI objects code
TexteditorColor$ = "white" texteditor #main.te, 5, 12, 430, 330 button #main.button2,"Start",[button2Click], UL, 445, 42, 96, 25 textbox #main.textbox8, 435, 12, 100, 25 button #main.button9,"Stop",[button9Click], UL, 445, 302, 96, 25
open "untitled" for window as #main print #main, "font ms_sans_serif 10" print #main, "trapclose [quit.main]"
#main.textbox8 "100000"
[main.inputLoop] 'wait here for input event wait
[button2Click] 'Perform action for the button named 'button2' #main.textbox8 "!contents? n" for i = 1 to n SCAN 'allows to break a loop. With a lower "Stop" button here, or window close [x] #main.te "Item ";i next wait
[button9Click] 'Perform action for the button named 'button9' goto [quit.main] wait
[quit.main] 'End the program close #main end
|
|
|
Post by cryptomen on Jan 3, 2024 9:31:48 GMT -5
Thank you!
I remember SCAN now.
I stopped programming in LB, so I need to warm up my engine)))
|
|
|
Post by cryptomen on Jan 3, 2024 9:46:11 GMT -5
I have another question.
How can we gracefully close any open files upon making a LONGJMP to SUB sQuit Handle$?
Ofcourse, maybe a GLOBAL OPNFILES$(100) may always be kept to add delete file handles as we open and close, and check from this list.
It would be great to have a CLOSEALL() function.
Is there any elegant tool for closing whatever open files upon receiving the Quit signal?
|
|
|
Post by tsh73 on Jan 3, 2024 11:03:02 GMT -5
I just tried if I open file and write to it and execute END it looks like BASIC closes all the files (and things I wrote got written there) Of cource it barks
, and so it is not elegant.
Probably having something global with list of handles will do (and arrays are always global by in LB). Also, you can skip "delete file handles" bit - just close files, handle errors and ignore them. (if it errors on closing, most likely it is already closed).
I write something, have a look.
global OPNFILES$
open "test1.txt" for output as #1 OPNFILES$ = OPNFILES$+" "+"#1" 'register handle to close, space delimited #1 "Hello file 1 ";time$()
open "test2.txt" for output as #2 OPNFILES$ = OPNFILES$+" "+"#2" 'register another handle to close #2 "Hello file 2 ";time$()
close #1
'so OPNFILES$ contains #1 and #2, but #1 is already closed
call CLOSEALL 'this will try to close all from OPNFILES$ ignoring errors
'see if files are here run "notepad.exe ";DefaultDir$;"\test1.txt" run "notepad.exe ";DefaultDir$;"\test2.txt"
end
sub CLOSEALL w$="*" while 1 i=i+1 w$=word$(OPNFILES$,i) if w$="" then exit sub 'no more files call tryClose w$ wend end sub
sub tryClose hnd$ on error goto [ignore] 'if it errors, probably already closed - OK then close #hnd$ [ignore] end sub
|
|
|
Post by cryptomen on Jan 4, 2024 13:08:50 GMT -5
Thank you. Yes, this is something like this I can implement.
|
|
|
Post by Brandon Parker on Jan 7, 2024 21:17:17 GMT -5
You could use something like this "closeHandle()" function. All you have to do is place a call to it with every handle that might be open. The only problem is that the debugger will halt when it encounters a handle that does not exist, but if you are using in the "Quit" function of the program, this probably will not be a huge issue.
This has always been my method of choice...
Global False : False = 0 Global True : True = 1
Open "Test.txt" For Output As #Test
Print closeHandle("#Test")
'This will halt the debugger if you use the debugger 'since it will see an error in the closeHandle() function 'when LB attempts to close the non-existent handle Print closeHandle("#Test2") End
Function closeHandle(handle$) On Error GoTo [Error] Close #handle$ closeHandle = True Exit Function [Error] End Function
{:0)
Brandon Parker
|
|