input()?

Just starting out? Need help? Post your questions and find answers here.
ppnl
User
User
Posts: 33
Joined: Thu Oct 13, 2011 8:08 am

input()?

Post by ppnl »

I was using the input() function to halt program execution so I could read output before the console closed. Like this:

Code: Select all

OpenConsole()

Input()
End 

CloseConsole()
Just hit enter to end the program. Works fine in the IDE. But compile and run the .EXE and instead of closing the program it starts a whole new instance of the program so that I have two consoles open.

Is this intended?
infratec
Always Here
Always Here
Posts: 7654
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: input()?

Post by infratec »

First:
What doy you think End means?

A command after End is non sense.

Second:
Have you choosen Console app in Compiler settings?

Third:
From which OS are you talking?
Axolotl
Addict
Addict
Posts: 865
Joined: Wed Dec 31, 2008 3:36 pm

Re: input()?

Post by Axolotl »

well, it is always a good idea to look at the docs/help.
Easy by pressing F1 on a keyword.
Anyway, I have done the following for your convenience:

Code: Select all

; Important Remark (borrowed from Help): 
;
; On Microsoft Windows, there are two different executable formats: Win32 and Console. 
;   If you want to create a standard console application, like 'dir', 'del' etc. you must compile 
;   the executable using the 'Console' format (Compiler Option menu in the PureBasic IDE). 
;
; On Linux and OS X, there is no special Console format however setting the Compiler option 
;   to 'Console' will launch a terminal window automatically when you run your program from the IDE. 
; 
Define name$ 

If OpenConsole() ; if result is 0, it has failed and all further call to console functions must be disabled.  

  Print("Please enter your name:   ")           ; Ask for name
  name$ = Input()                               ; Wait for user input

  PrintN("Hello " + name$) 
  PrintN("")

; PrintN("Press return to exit")
  PrintN("Press return to close console")
  Input() ; Wait for Enter/Return Key pressed by user w/o any other keys before 

  CloseConsole()
EndIf 

; acc. to help: 
;
; End .. Ends the program execution correctly. 
;        The 'ExitCode' optional parameter can be specified if the program need to returns an error code. 
;
End ;ExitCode 
Just because it worked doesn't mean it works.
PureBasic 6.04 (x86) and <latest stable version and current alpha/beta> (x64) on Windows 11 Home. Now started with Linux (VM: Ubuntu 22.04).
Post Reply