To use this website fully, you first need to accept the use of cookies. By agreeing to the use of cookies you consent to the user of functional cookies. For more information read this page.

Basic input methods

VB.NET also has a collection of very simple ways of collecting an input. The following examples will outline the input methods available in VB.NET.

Console

The console can also be used for input. However, to create a console that accepts input, the Console Application project must be selected.

Console project

Console input comes from when the user inserts some text and presses the ENTER/RETURN key.

Console.Read

Console.Read is designed to read a character from the console input when the user presses ENTER/RETURN. It will return an integer equivalent to the ASCIIAmerican Standard Code for Information Interchange defines how characters are represented. For instance the character 'a' is represented by the ASCII number 97. It has be widely replaced by Unicode. code for the character.

VB.NET
Console.Read()
		

This will take an input of any kind and return the integer form which can then be stored in a variable.

Console.ReadLine

Console.ReadLine works similarly to Console.Read bar the fact that it returns a string. The string just contains the information that was inserted into the console.

VB.NET
Console.ReadLine()
		

Inputs from the user interface

InputBox

The class found at Microsoft.VisualBasic.Interaction contains a very simple set of methods. One of these methods is a function that returns a string that is called InputBox.

The InputBox function is very simple and limited. Its properties such as TopMost or BackgroundColor cannot be modified, which leads to all sorts of interface issues.

However, it is a simple way of testing an input. For this reason, some developers do use it in development, but for mainstream use, it is limited to very simple applications. The following sample demonstrates the use of an InputBox and stores the result in a string variable.

VB.NET
Dim s As String
s = InputBox("Please insert your name", "First application")
		

InputBox can also have other arguments demonstrated below:

InputBox(prompt As String, [title As String],[DefaultResponse As String], [XPos As Integer], [YPos As Integer])

DefaultResponse is used to put a default value into the InputBox whereas XPos and YPos define the coordinates of the InputBox horizontally and vertically, respectively.

Other input methods

Of course the user interface can be used to create input methods such as ones using the TextBox control along with loads of others. However, this is not for this article.

As well as this, custom class libraries such as the one found here (BBCL) also have custom input box styled dialogs.

  • Create a program that asks the user for their name and displays it on the screen through the use of an information dialog.