Visual Basic .NET ArrayVisual Basic .NET BackgroundWorkerVisual Basic .NET ByVal and ByRef keywordsVisual Basic .NET ClassesVisual Basic .NET ConditionsVisual Basic .NET Connection HandlingVisual Basic .NET ConsoleVisual Basic .NET Data AccessVisual Basic .NET DateVisual Basic .NET Debugging your applicationVisual Basic .NET Declaring variablesVisual Basic .NET DictionariesVisual Basic .NET Disposable objectsVisual Basic .NET EnumVisual Basic .NET Error HandlingVisual Basic .NET Extension methodsVisual Basic .NET File HandlingVisual Basic .NET File/Folder CompressionVisual Basic .NET FTP serverVisual Basic .NET FunctionsVisual Basic .NET GDI+Visual Basic .NET GenericsVisual Basic .NET Google Maps in a Windows FormVisual Basic .NET IntroductionVisual Basic .NET Introduction to SyntaxVisual Basic .NET LINQVisual Basic .NET ListsVisual Basic .NET LoopingVisual Basic .NET MultithreadingVisual Basic .NET NullReferenceExceptionVisual Basic .NET OOP KeywordsVisual Basic .NET OperatorsVisual Basic .NET Option ExplicitVisual Basic .NET Option InferVisual Basic .NET Option StrictVisual Basic .NET RandomVisual Basic .NET Reading compressed textfile on-the-flyVisual Basic .NET RecursionVisual Basic .NET ReflectionVisual Basic .NET Short-Circuiting Operators (AndAlso - OrElse)Visual Basic .NET Task-based asynchronous patternVisual Basic .NET ThreadingVisual Basic .NET Type conversionVisual Basic .NET Unit Testing in VB.NETVisual Basic .NET Using axWindowsMediaPlayer in VB.NetVisual Basic .NET Using BackgroundWorkerVisual Basic .NET Using StatementVisual Basic .NET WinForms SpellCheckBoxVisual Basic .NET Working with Windows FormsVisual Basic .NET WPF XAML Data BindingVisual Basic 14.0 Features

Visual Basic .NET Console

From WikiOD

Console.ReadLine()[edit | edit source]

Dim input as String = Console.ReadLine()

Console.ReadLine() will read the console input from the user, up until the next newline is detected (usually upon pressing the Enter or Return key). Code execution is paused in the current thread until a newline is provided. Afterwards, the next line of code will be executed.

Console.WriteLine()[edit | edit source]

Dim x As Int32 = 128
Console.WriteLine(x) ' Variable '
Console.WriteLine(3) ' Integer '
Console.WriteLine(3.14159) ' Floating-point number '
Console.WriteLine("Hello, world") ' String '
Console.WriteLine(myObject) ' Outputs the value from calling myObject.ToString()

The Console.WriteLine() method will print the given argument(s) with a newline attached at the end. This will print any object supplied, including, but not limited to, strings, integers, variables, floating-point numbers.

When writing objects that are not explicitly called out by the various WriteLine overloads (that is, you are using the overload that expects a value of type Object, WriteLine will use the .ToString() method to generate a String to actually write. Your custom objects should OverRide the .ToString method and produce something more meaningful than the default implementation (which typically just writes the fully qualified type name).

Console.Read()[edit | edit source]

Dim inputCode As Integer = Console.Read()

Console.Read() awaits input from the user and, upon receipt, returns an integer value corresponding with the character code of the entered character. If the input stream is ended in some way before input can be obtained, -1 is returned instead.

Console.ReadKey()[edit | edit source]

Dim inputChar As ConsoleKeyInfo = Console.ReadKey()

Console.ReadKey() awaits input from the user and, upon receipt, returns an object of class ConsoleKeyInfo, which holds information relevant to the character which the user provided as input. For detail regarding the information provided, visit the MSDN documentation.

Prototype of command line prompt[edit | edit source]

Module MainPrompt
Public Const PromptSymbol As String = "TLA > "
Public Const ApplicationTitle As String = GetType(Project.BaseClass).Assembly.FullName
REM Or you can use a custom string
REM Public Const ApplicationTitle As String = "Short name of the application"

Sub Main()
    Dim Statement As String
    Dim BrokenDownStatement As String()
    Dim Command As String
    Dim Args As String()
    Dim Result As String

    Console.ForegroundColor = ConsoleColor.Cyan
    Console.Title = ApplicationTitle & " command line console"

    Console.WriteLine("Welcome to " & ApplicationTitle & "console frontend")
    Console.WriteLine("This package is version " & GetType(Project.BaseClass).Assembly.GetName().Version.ToString)

    Do While True
        Statement = Console.ReadLine()
        BrokenDownStatement = Statement.Split(" ")
        ReDim Args(BrokenDownStatement.Length - 1)
        Command = BrokenDownStatement(0)

        For i = 1 To BrokenDownStatement.Length - 1
            Args(i - 1) = BrokenDownStatement(i)

        Select Case Command.ToLower
            Case "example"
                Result = DoSomething(Example)
            Case "exit", "quit"
                Exit Do
            Case "ver"
                Result = "This package is version " & GetType(Project.BaseClass).Assembly.GetName().Version.ToString
            Case Else
                Result = "Command not acknowldged: -" & Command & "-"
        End Select
        Console.WriteLine(" " & Result)

    Console.WriteLine("I am exiting, time is " & DateTime.Now.ToString("u"))
End Sub
End Module

This prototype generate a basic command line interpreter.

It automatically get the application name and version to communicate to the user. For each input line, it recognize the command and an arbitrary list of arguments, all separated by space.

As a basic example, this code understand ver, quit and exit commands.

The parameter Project.BaseClass is a class of your project where the Assembly details are set.

Console.Write()[edit | edit source]

Dim x As Int32 = 128
Console.Write(x) ' Variable '
Console.Write(3) ' Integer '
Console.Write(3.14159) ' Floating-point number '
Console.Write("Hello, world") ' String '

The Console.Write() method is identical to the Console.WriteLine() method except that it prints the given argument(s) without a newline attached at the end. This method can be made functionally identical to WriteLine by adding a newline string to the end of any arguments provided:

Console.Write("this is the value" & Environment.NewLine)