Search code examples
vb.netvisual-studio-2012commandprompt

Creating a by letter effect with visual studio


I would like to create an effect in visual studio where text shows up on the screen not all at once, but letter by letter with a certain amount of time between each letter appearing. I plan to open a different module that will have this code in it from my main module. Any ideas? Here is my coding so far. I am making a command prompt.

Public Sub Main()
    Dim line As String
    Console.Title = "Command"
    Console.WriteLine("Microsoft Windows [Version 6.3.9600]")
    Console.WriteLine("<c> 2013 Microsoft Corporation. All right reserved.")
    Console.WriteLine(" ")
    Do
        Console.Write("C:\Users\Bob>")
        Line = Console.ReadLine()
        If line = "help" Then
            Console.WriteLine("hello world")
            Console.WriteLine(" ")
        ElseIf line = "help1" Then
            Console.WriteLine("hello again, world!")
            Console.WriteLine(" ")
        ElseIf line = "exit" Then
            Environment.Exit(0)
        Else
            Console.WriteLine("Command not found.")
            Console.WriteLine(" ")
        End If
    Loop While line IsNot Nothing
End Sub

Solution

  • Just replace all of your Console.WriteLine with Marquee("Text here")

    Update: As Walt points out in the comments it should be noted this approach will lock up the application until the text has finished displaying. If this is not desired then you should think about offloading it to another thread or creating a timer event.

         Sub Main()
    
                Marquee("Hello World")
                Console.ReadLine()
    
        End Sub
    
        Sub Marquee(StringToWrite As String)
    
            For i As Integer = 0 To StringToWrite.Length - 1
                Console.Write(StringToWrite.Substring(i, 1))
                Threading.Thread.Sleep(200)
            Next
    
    
    
        End Sub