Search code examples
vb.netconsolebasic

Visual Basic console - Making text type itself out


I'm totally cold on this so I have no idea how I would even start coding something like this except for the part that I think it might use some kind of a timer. Basicly I want the text to type itself out on the console so say that a basic Console.WriteLine ("Hello world") would take 5 seconds to write itself (so 2 letters per second). Is there a command that does something like this? Or do I have to make some (hopefully not) complex timer based Sub that will write the text out for me?

Thanks in advance!


Solution

  • Use this code to get the effect:

    Sub ConsoleType(stringToWrite As String, delay As Integer)
        For Each i As Char In stringToWrite
            Console.Write(i)
            Threading.Thread.Sleep(delay)
        Next
    End Sub
    

    Call the function ConsoleType and it will be 'typed'. Note that the delay is in milliseconds. Since you want the speed of 2 Letters/sec, you could use a value of 500.