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.
The console can also be used for input. However, to create a console that accepts input, the Console Application project must be selected.
Console input comes from when the user inserts some text and presses the ENTER/RETURN key.
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.
This will take an input of any kind and return the integer form which can then be stored in a variable.
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
Inputs from the user interface
The class found at
contains a very simple set of methods. One of these methods
is a function that returns a string that is called
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
stores the result in a string variable.
Dim s As String s = InputBox("Please insert your name", "First application")
InputBox can also have other arguments
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
whereas XPos and YPos define the coordinates of the
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.
- Create a program that asks the user for their name and displays it on the screen through the use of an information dialog.