hal9k
Junior Member
Posts: 87
|
Post by hal9k on Aug 3, 2023 19:20:57 GMT -5
Hi, I have a text window that I use for creating reports. I may need to open & close the window multiple times per session. I'm trying to control this with a flag variable that is set when the window is open. I want to turn off the flag if the window is closed. I used a trapclose like this: PRINT #Reports, "trapclose [Quit.Reports]" to know when the window has been closed.
The problem is that the trapclose doesn't seem to be working. One of the symptoms is that the string "trapclose [Quit.Reports]" is included at the top of the text window. The other symptom is that my flag variable is NOT getting reset.
Does anybody know if there is an issue with trapclose for text windows? Failing that is there another test I can use to determine if the text window is currently open?
Thanks, as always!
|
|
|
Post by xxgeek on Aug 4, 2023 0:14:32 GMT -5
What's happening hal9k is, since a text window accepts text strings like "trapclose [Quit.Reports]" or any other string, and prints them directly on the window there is a special character that precedes when the string is actually a command.
Print #Reports, "!trapclose [Quit.Reports]"
|
|
|
Post by Walt Decker on Aug 4, 2023 8:26:27 GMT -5
To be a little more specific:
' GLOBAL TextWinOpen
OPEN "Bah" FOR TEXT AS #TXTWIN PRINT #TXTWIN, "!TRAPCLOSE [CLOSE.TEXT.WIN]"
TextWinOpen = 1 '<--- SET OPEN FLAG
[BEGIN.WAIT] WAIT
[CLOSE.TEXT.WIN] CLOSE #TXTWIN
TextWinOpen = 0 '<--- RESET OPEN FLAG
GOTO [BEGIN.WAIT]
'
|
|
hal9k
Junior Member
Posts: 87
|
Post by hal9k on Aug 4, 2023 10:26:57 GMT -5
Thanks, guys. I could have sworn I tried that before bothering you. It now works great.
|
|
|
Post by Walt Decker on Aug 4, 2023 11:29:59 GMT -5
By the way, there is a test you can perform to check if a window is open: '
RetVal = FN.GetHndl("SOMEWINDOWTAG")
IF RetVal = 0 THEN ' DO SOMETHING ELSE END IF
'DO WHATEVER
END
'---------------------------- '----------------------------
FUNCTION FN.CheckTag$(WinHndl$) '################################################# ' THIS CHECKS FOR PROPER SYNTAX ' IT DOES NOT MATTER WHETHER THE WINDOW IS A ' FORM OR CONTROL '#################################################
IF LEFT$(WinHndl$, 1) <> "#" THEN WinHndl$ = "#" + WinHndl$
FN.CheckTag$ = WinHndl$ '<--- this was CheckTag$; changed to FN.CheckTag$ END FUNCTION
'---------------------------- '----------------------------
FUNCTION FN.GetHndl(WinHndl$) '################################################# ' THIS CHECKS FOR AN ACTIVE WINDOW ' IT DOES NOT MATTER WHETHER THE WINDOW ' IS A FORM OR CONTROL ' ' IF THE HANDLE IS NO LONGER ACTIVE, I. E. OPEN ' FUNCTION HWND() WILL RETURN ZERO AND WILL ' PRODUCE AN ERROR. THE "ON ERROR" STATEMENT ' IS THEN ACTIVATED AND THE CODE JUMPS TO THE ' ERROR HANDLER [HANDLE.ERROR] AND THE FUNCTION ' RETURNS ZERO '#################################################
Hndl = 0
WinHndl$ = FN.CheckTag$(WinHndl$)
ON ERROR GOTO [HANDLE.ERROR]
Hndl = HWND(#WinHndl$)
FN.GetHndl = Hndl EXIT FUNCTION
[HANDLE.ERROR]
FN.GetHndl = 0 END FUNCTION
'----------------------------- '----------------------------- '
EDIT: Saw an error in the code; check FN.CheckTag$() for correction
|
|