OpenConsole() with mode but no title?

Just starting out? Need help? Post your questions and find answers here.
mikejs
Enthusiast
Enthusiast
Posts: 166
Joined: Thu Oct 21, 2010 9:46 pm

OpenConsole() with mode but no title?

Post by mikejs »

I have a console utility that needs to deal with ascii files (because of other programs/scripts that will be supplying those files or reading them afterwards). The console output may also be redirected to an existing ascii log file. So, it seems sensible to supply #PB_Ascii in the Mode parameter of OpenConsole().

But, Mode is the second parameter - the first being Title$. I don't want to alter the existing title of the console I'll be running inside - I want to leave the existing title unchanged.

Both Mode and Title$ are optional parameters, but I don't see a way to provide Mode without first providing Title$. Is there a special value I can pass for the title that keeps the existing value or some other syntax to provide a value for a later optional parameter without having to pass a value for the earlier ones?

PB clearly knows how to leave the title as-is, because that's what happens with plain OpenConsole(), no parameters provided. I don't see a PB native way to read the existing title to restore it either (and even if there was, I would probably have to call OpenConsole() first, at which point I'm too late - the existing title has been overwritten).

Any suggestions? Am I missing something obvious?
User avatar
RSBasic
Moderator
Moderator
Posts: 1218
Joined: Thu Dec 31, 2009 11:05 pm
Location: Gernsbach (Germany)
Contact:

Re: OpenConsole() with mode but no title?

Post by RSBasic »

Workaround for Windows:

Code: Select all

EnableExplicit

Define ConsoleTitle$ = Space(1024)

If OpenConsole()
  GetConsoleTitle_(@ConsoleTitle$, 1024)
  CloseConsole()
EndIf

If OpenConsole(ConsoleTitle$, #PB_Ascii)
  
  Input()
  
  CloseConsole()
EndIf
Image
Image
mikejs
Enthusiast
Enthusiast
Posts: 166
Joined: Thu Oct 21, 2010 9:46 pm

Re: OpenConsole() with mode but no title?

Post by mikejs »

That looks like it might do the trick - thanks.

I assume I'm right though in that there is no way in PB to supply a later optional parameter without also supplying the earlier optional ones? Bit of a rare case, but it would be useful sometimes.
User avatar
RSBasic
Moderator
Moderator
Posts: 1218
Joined: Thu Dec 31, 2009 11:05 pm
Location: Gernsbach (Germany)
Contact:

Re: OpenConsole() with mode but no title?

Post by RSBasic »

mikejs wrote:I assume I'm right though in that there is no way in PB to supply a later optional parameter without also supplying the earlier optional ones? Bit of a rare case, but it would be useful sometimes.
Yes, that's not possible.
This is possible in other programming languages. Example:

Code: Select all

MyFunction(Parameter1, , , Parameter4)
That would be very useful.

A wish thread already exists: viewtopic.php?f=3&t=60551
Nobody knows when this syntax function will be implemented. :(
Image
Image
Post Reply