Loading ...
Sorry, an error occurred while loading the content.

Re: How do I get a whole line of text back from the read routine?

Expand Messages
  • Brent Thorn
    ... Hello John, I re-made the previous demo for more complete input gathering; waiting until it sees a CR or LF. It will print the user s input to LB s main
    Message 1 of 4 , Jun 30, 2006
    • 0 Attachment
      --- In libertybasic@yahoogroups.com, "John Boyd" <jboyd333@...> wrote:
      >
      > Brent,
      >
      > Thanks a lot for the example! I typed it in, and it works in that
      > it opens a console window and gives the message "Press ENTER to
      > close this window." So far so good, and I see that the contents of
      > buffer$ was written to the console. That's just what I need for
      > that part.
      >
      > But when I press ENTER, I would like to get back the "stdin"
      > contents that the user typed. When I print out buffer$, I only get
      > the first character of what I typed in. I'd like to get a whole
      > line of input if possible, which is what the GUI interface will be
      > sending back to the chess engine.
      >
      > Is there a way to modify the calls to do that?
      >
      > thanks!!
      >
      > John
      >

      Hello John,

      I re-made the previous demo for more complete input gathering;
      waiting until it sees a CR or LF. It will print the user's input to
      LB's main window. (Watch out for weird focus issues.) If your app
      doesn't need the console window, you can probably remove the calls
      that "alloc" and "free" it.

      Brent

      Bay 6 Software - http://www.b6sw.com/

      'START CODE
      CallDLL #kernel32, "AllocConsole", _
      success As ULong

      If success = 0 Then
      Print "Error"
      End
      End If

      CallDLL #kernel32, "GetStdHandle", _
      _STD_INPUT_HANDLE As ULong, _
      hStdIn As ULong

      CallDLL #kernel32, "GetStdHandle", _
      _STD_OUTPUT_HANDLE As ULong, _
      hStdOut As ULong

      buffer$ = "Please type some text: "
      buflen = Len(buffer$)

      Struct bytes, number As ULong

      CallDLL #kernel32, "WriteFile", _
      hStdOut As ULong, _
      buffer$ As Ptr, _
      buflen As ULong, _
      bytes As Struct, _
      0 As Long, _
      success As Long

      result$ = ""
      Do

      buflen = 80
      buffer$ = Space$(buflen)

      CallDLL #kernel32, "ReadFile", _
      hStdIn As ULong, _
      buffer$ As Ptr, _
      buflen As ULong, _
      bytes As Struct, _
      0 As Long, _
      success As Long

      If success = 0 Or bytes.number.struct = 0 Then Exit Do

      result$ = result$ + Left$(buffer$, bytes.number.struct)

      Loop Until Asc(Right$(result$, 1)) <= 13

      CallDLL #kernel32, "FreeConsole", _
      success As Long

      Print result$

      End
      'END CODE
    Your message has been successfully submitted and would be delivered to recipients shortly.