Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Strange behavior readline

Strange behavior readline

Scheduled Pinned Locked Moved Visual Basic
tutorialquestion
5 Posts 3 Posters 7 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    JR212
    wrote on last edited by
    #1

    Hi I've wrote this code

    With NewHS
    .Lines = nLijnen
    .PlayDate = Now
    Console.SetCursorPosition(10, 21)
    Console.Write("New highscore. " & nLijnen & " Your name please? ")
    .Name = Console.ReadLine
    .Name = .Name.Trim
    If .Name = "" Then .Name = "[No Name]"
    End With

    When running the line console.readline It asks for two enters to accept. I see the cursor movingto the begin of the next line by the first enter. The second time the program runs those lines of code it working well with one enter. I'm clearing the keyboardbuffer before starting writing to the console with

    Sub ClearKBBuffer()
    While Console.KeyAvailable
    Console.ReadKey(True)
    Console.ReadKey()
    End While
    End Sub

    Any Idea why or how to solve this. Jan

    L A 2 Replies Last reply
    0
    • J JR212

      Hi I've wrote this code

      With NewHS
      .Lines = nLijnen
      .PlayDate = Now
      Console.SetCursorPosition(10, 21)
      Console.Write("New highscore. " & nLijnen & " Your name please? ")
      .Name = Console.ReadLine
      .Name = .Name.Trim
      If .Name = "" Then .Name = "[No Name]"
      End With

      When running the line console.readline It asks for two enters to accept. I see the cursor movingto the begin of the next line by the first enter. The second time the program runs those lines of code it working well with one enter. I'm clearing the keyboardbuffer before starting writing to the console with

      Sub ClearKBBuffer()
      While Console.KeyAvailable
      Console.ReadKey(True)
      Console.ReadKey()
      End While
      End Sub

      Any Idea why or how to solve this. Jan

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      I just tried your initial code (with various responses) and it works with only one press of the Enter key.

      J 1 Reply Last reply
      0
      • J JR212

        Hi I've wrote this code

        With NewHS
        .Lines = nLijnen
        .PlayDate = Now
        Console.SetCursorPosition(10, 21)
        Console.Write("New highscore. " & nLijnen & " Your name please? ")
        .Name = Console.ReadLine
        .Name = .Name.Trim
        If .Name = "" Then .Name = "[No Name]"
        End With

        When running the line console.readline It asks for two enters to accept. I see the cursor movingto the begin of the next line by the first enter. The second time the program runs those lines of code it working well with one enter. I'm clearing the keyboardbuffer before starting writing to the console with

        Sub ClearKBBuffer()
        While Console.KeyAvailable
        Console.ReadKey(True)
        Console.ReadKey()
        End While
        End Sub

        Any Idea why or how to solve this. Jan

        A Offline
        A Offline
        Alan N
        wrote on last edited by
        #3

        Sub ClearKBBuffer()
        While Console.KeyAvailable
        Console.ReadKey(True)
        Console.ReadKey()
        End While
        End Sub

        Surely that will block when there are an odd numbers of keys in the input queue. Did you mean this

        Sub ClearKBBuffer()
        While Console.KeyAvailable
        Console.ReadKey(True)
        End While
        End Sub

        Alan.

        J 1 Reply Last reply
        0
        • A Alan N

          Sub ClearKBBuffer()
          While Console.KeyAvailable
          Console.ReadKey(True)
          Console.ReadKey()
          End While
          End Sub

          Surely that will block when there are an odd numbers of keys in the input queue. Did you mean this

          Sub ClearKBBuffer()
          While Console.KeyAvailable
          Console.ReadKey(True)
          End While
          End Sub

          Alan.

          J Offline
          J Offline
          JR212
          wrote on last edited by
          #4

          That was stupit wasn't it :)

          1 Reply Last reply
          0
          • L Lost User

            I just tried your initial code (with various responses) and it works with only one press of the Enter key.

            J Offline
            J Offline
            JR212
            wrote on last edited by
            #5

            The whole code where start is the real game <TargetFramework>net6.0</TargetFramework>

            Sub ClearKBBuffer()
                While Console.KeyAvailable
                    Console.ReadKey(True)
                End While
            End Sub
            Sub Main()
                Dim k As ConsoleKey
                Console.TreatControlCAsInput = True
                Randomize()
                Do
                    Console.CursorVisible = False
                    Dim nLijnen = Start()
                    ClearKBBuffer
                    Console.CursorVisible = True
                    Dim hs As HighScores = HighScores.Load()
                    Console.BackgroundColor = ConsoleColor.Red
                    Console.ForegroundColor = ConsoleColor.Black
                    Dim NewPLace As Integer = -1
                    For i As Integer = 0 To 9
                        If nLijnen > hs.Scores(i).Lines And NewPLace < 0 Then
                            NewPLace = i
                        End If
                        Console.SetCursorPosition(10, 10 + i)
                        Console.Write(hs.Scores(i).Name.PadRight(30) & hs.Scores(i).Lines.ToString.PadLeft(10) & "   " & hs.Scores(i).PlayDate.ToString("dd/MM/yyyy HH:mm:ss"))
                    Next
                    Console.Beep()
                    If NewPLace >= 0 Then
                        Dim NewHS As New Score
                        With NewHS
                            .Lines = nLijnen
                            .PlayDate = Now
                            Console.SetCursorPosition(10, 21)
                            Console.Write("New highscore. " & nLijnen & " Your name please? ")
                            .Name = Console.ReadLine
                            .Name = .Name.Trim
                            If .Name = "" Then .Name = "\[No Name\]"
                        End With
                        For i = 8 To NewPLace Step -1
                            hs.Scores(i + 1) = hs.Scores(i)
                        Next
                        hs.Scores(NewPLace) = NewHS
                        hs.Save()
                    End If
                    Console.SetCursorPosition(0, Console.WindowHeight - 2)
                    Console.WriteLine("New game? (Y/N) ")
                    Do
                        k = Console.ReadKey.Key
                    Loop While k <> ConsoleKey.Y And k <> ConsoleKey.N
                Loop While k = ConsoleKey.Y
            End Sub
            
            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups