Author Topic: [FIXED] Odd interaction of the "Clear" command with display of console window  (Read 3871 times)

0 Members and 1 Guest are viewing this topic.

This topic contains a post which is marked as Best Answer. Press here if you would like to see it.

Offline hanness

  • Forum Regular
  • Posts: 210
    • View Profile
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?




« Last Edit: March 17, 2021, 07:57:11 am by odin »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Odd interaction of the "Clear" command with display of console window
« Reply #1 on: March 15, 2021, 11:37:05 pm »
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
« Last Edit: March 15, 2021, 11:47:24 pm by bplus »

Offline hanness

  • Forum Regular
  • Posts: 210
    • View Profile
Re: Odd interaction of the "Clear" command with display of console window
« Reply #2 on: March 16, 2021, 12:55:28 am »
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.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Odd interaction of the "Clear" command with display of console window
« Reply #3 on: March 16, 2021, 08:42:53 am »
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
Quote
RUN is a control flow statement that clears and restarts the program currently in memory or executes another specified program.

Offline SpriggsySpriggs

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • View Profile
    • GitHub
Re: Odd interaction of the "Clear" command with display of console window
« Reply #4 on: March 16, 2021, 12:07:32 pm »
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.
« Last Edit: March 16, 2021, 01:44:42 pm by SpriggsySpriggs »
Shuwatch!

Offline SpriggsySpriggs

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • View Profile
    • GitHub
Re: Odd interaction of the "Clear" command with display of console window
« Reply #5 on: March 16, 2021, 03:41:10 pm »
@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.
Shuwatch!

Offline hanness

  • Forum Regular
  • Posts: 210
    • View Profile
Re: Odd interaction of the "Clear" command with display of console window
« Reply #6 on: March 16, 2021, 10:39:21 pm »
Fantastic! Thanks so much for the help.

How will I know when this is fixed? Will this thread be updated?

Offline SpriggsySpriggs

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • View Profile
    • GitHub
Re: Odd interaction of the "Clear" command with display of console window
« Reply #7 on: March 16, 2021, 10:49:38 pm »
@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.
Shuwatch!

Marked as best answer by hanness on March 17, 2021, 12:21:03 pm

FellippeHeitor

  • Guest

Offline SpriggsySpriggs

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • View Profile
    • GitHub
Re: Odd interaction of the "Clear" command with display of console window
« Reply #9 on: March 16, 2021, 10:54:00 pm »
Hahaha I spoke too soon! Yep, just download the dev build above and you should be good
Shuwatch!

Offline hanness

  • Forum Regular
  • Posts: 210
    • View Profile
Re: Odd interaction of the "Clear" command with display of console window
« Reply #10 on: March 17, 2021, 01:00:19 am »
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!