a prompt for input in c.l. application

Post

Posted
Rating:
#1 (In Topic #1137)
Trainee
 Sorry for an elementary question. I am programming for 50 years, but it is my first experience with Gambas. How can I ask user to enter a number and get their input on the same line of the terminal?
In Basic it would be
Input "Invitation phrase",#filenumber, variable. In Gambas it seems there is no  "invitation phrase". Is there any way to achieve the same result?
Online now: No Back to the top

Post

Posted
Rating:
#2
Guru
BruceSteers is in the usergroup ‘Guru’

ail_gu said

Sorry for an elementary question. I am programming for 50 years, but it is my first experience with Gambas. How can I ask user to enter a number and get their input on the same line of the terminal?
In Basic it would be
Input "Invitation phrase",#filenumber, variable. In Gambas it seems there is no  "invitation phrase". Is there any way to achieve the same result?

for a terminal applications look at File.In and File.Out and the File.In.ReadLine() Method.

File.In and File.Out point to stdin and stdout respectively.

Something like this should work…

Code (gambas)

  1. Public Sub Main()
  2.  
  3.   Dim sTxt As String
  4.  
  5.   Print "type something below.."
  6.  
  7.   sTxt = File.In.ReadLine()  ' read a line from stdin
  8.  
  9.   Print "the text typed was: " & sTxt
  10.  
  11.  
  12.  

I am not sure how to not put in a linefeed with the output text, if i used
Print "question: "; then the end semicolon should not make it insert a linefeed but it makes the text not show at all :-\
Online now: No Back to the top

Post

Posted
Rating:
#3
Guru
BruceSteers is in the usergroup ‘Guru’

BruceSteers said


I am not sure how to not put in a linefeed with the output text, if i used
Print "question: "; then the end semicolon should not make it insert a linefeed but it makes the text not show at all :-\

Okay i got the answer for single line method now…

Code (gambas)

  1.  
  2.  
  3.  ' print a question to stdout with no linefeed as line ends with ;
  4. Print "This Question: ";
  5.  
  6. ' Flushing stdout is required to display the text (this is what i was missing)
  7. Flush #File.Out
  8.  
  9. ' read answer from stdin
  10. sTxt = File.In.ReadLine()  
  11.  
  12. Print "You answered " & sTxt
  13.  
  14.  

Note: some gambas native commands like Read , Write, Flush, etc require the hash # prefix with their arguments to denote a file pointer.
hence the
Flush #File.Out
Online now: No Back to the top

Post

Posted
Rating:
#4
Regular
vuott is in the usergroup ‘Regular’
In addition to "File.In.ReadLine()" you can also use "Input":

Code (gambas)

  1. Public Sub Main()
  2.  
  3.    Dim s As String
  4.  
  5.    Write "type something here: "
  6.    Flush
  7.  
  8.    Input s
  9.  
  10.    Print "the text typed was: "; s
  11.  

Europaeus sum !

<COLOR color="#FF8000">Amare memorentes atque deflentes ad mortem silenter labimur.</COLOR>
Online now: No Back to the top
1 guest and 0 members have just viewed this.