QB64.org Forum
Active Forums => QB64 Discussion => Topic started by: hanness on March 15, 2021, 05:24:30 pm
-
I'm writing a program that uses a very large number of variables. When the program completes, it returns to the start of the program where it displays a menu of options for the user. Each time the program returns to the start, I want to issue a "Clear" command to clean up all the variables that have been in use. However, I'm having a problem with "Clear" interacting with the console in a way that I cannot explain.
NOTE: I am using QB64 1.5 64-bit on Windows 10 20H2
Take a look at this code sample:
Option _Explicit
ProgramBegin:
$Console:Only
_Source _Console
Rem $Dynamic
Width 120, 30
Option Base 1
Clear
Dim a As String
Input "Enter some text (anything is fine): "; a$
Print "You entered: "; a$
Input a$ ' This line is only here to pause program execution
GoTo ProgramBegin
If I run the above code, a window opens but I never see any text at all. In other words, the prompt for the "Input" on line 12 is never displayed. Without the "Clear" command it displays just fine.
Now, look at the following code. The only difference is that I move the "Clear" command to a few lines earlier in the program:
Option _Explicit
ProgramBegin:
Clear
$Console:Only
_Source _Console
Rem $Dynamic
Width 120, 30
Option Base 1
Dim a As String
Input "Enter some text (anything is fine): "; a$
Print "You entered: "; a$
Input a$ ' This line is only here to pause program execution
GoTo ProgramBegin
This time, when I run the program, I get the following error:
--------------------------
Unhandled Error #258
Line: 5 (in main module)
Invalid handle
Continue?
--------------------------
Note that line 5 is the one that reads "$Console:Only". So again, it seems to have some sort of negative interaction with the console. Can anyone help me to understand what may be happening here? Is it simply not possible to use the "Clear" command when a console window is used?
-
I think Console has it's own set of commands, have you consulted Wiki?
I think @SMcNeill was doing things with Console, don't remember if it was his own private experiments or if the changes were included in a Dev version, there was some discussion a several months back. Could consult QB64 change log. (I just checked Wiki Console and didn't get much about all the extra commands discussed. )
https://www.qb64.org/wiki/Console_Window
-
Thanks for the response, but maybe I should clarify just a little further.
I have a program of about 10,000 lines - the entire program makes use of the console only and it works flawlessly, so I'm pretty familiar with how that works.
I am simply trying to add one line of code with a single keyword, namely "clear". The "clear" command is supposed to simply erase variables - the docs don't indicate that it should in any way effect graphics or console output.
-
Thanks for the response, but maybe I should clarify just a little further.
I have a program of about 10,000 lines - the entire program makes use of the console only and it works flawlessly, so I'm pretty familiar with how that works.
I am simply trying to add one line of code with a single keyword, namely "clear". The "clear" command is supposed to simply erase variables - the docs don't indicate that it should in any way effect graphics or console output.
10K Console programming! You might be interfacing with Windows, hot sweaty interfacing ;-))
I wonder if you just Run your program again, if that will clear the deck?
From Wiki RE: Run
RUN is a control flow statement that clears and restarts the program currently in memory or executes another specified program.
-
I can confirm. I ran your code and saw the same results. I never use the Clear command so I have never had this issue. Maybe @FellippeHeitor knows what's happening? I have a feeling it comes from the sub_close call in sub_clear when it is used to kill all open file handles.
-
@hanness I have made a pull request on GitHub. I found the bug and it's a simple fix. It wasn't exactly where I thought it was but Fellippe found the function that was the culprit.
-
Fantastic! Thanks so much for the help.
How will I know when this is fixed? Will this thread be updated?
-
@hanness Not sure when the dev build will be released but you can go on GitHub and download the code as a zip and run the setup batch file to run the latest code for now.
-
Out now: https://www.qb64.org/portal/development-build/
-
Hahaha I spoke too soon! Yep, just download the dev build above and you should be good
-
Thank you, Gentlemen! This is truly fantastic responsiveness.
I would have been happy just knowing that this was on the "to do" list, but this is great!