Basic output methods
There are several very simple ways of outputting information to the user or to the debugger. Some forms are obtrusive outputs and some are unobtrusive.
An obtrusive output means that the program stops running the main sequence whilst the output is displayed whereas an unobtrusive output does not stop the main execution.
The console is a form of collecting multiple outputs for reference. Output here is unobtrusive.
Console.Write method is used to output any information
of any of 17 types (for instance, boolean, integer, single) on to
a line without taking a new line.
Below is a sample write command:
Console.Write("Hello world") Console.Write("This is a test")
Console.WriteLine method is used to output
some text and take a line break after it. This way multiple outputs
do not get mixed up as easily as shown above.
Console.WriteLine("Hello world") Console.WriteLine("This is a test")
Dialog based output
Dialog based output such as message boxes tends to be obtrusive output - it breaks execution of the program.
One of the simple forms of output is to use
simply takes up to three arguements as follows:
MsgBox(prompt As String, [Buttons As MsgBoxStyle] [title As String])
The prompt parameter is used to contain a message as a string and title is an optionalMeaning it does not need to be included, instead the compiler gives it a default value. parameter. Below is a sample:
The other option that was given was the Buttons option. This option is used to specify how the message box looks. Below is a table showing all types of message box. All samples are from Windows 7.
MsgBox method is quite limited, whereas the
class is more feature rich and customisable. One of the lacking
features of the
MsgBox method is that it does not support both
an icon and special buttons.
is not a default included method but a class it
does not work the same way. The following sample illustates
MessageBox.Show("Hello world!", "Sample program", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1)
Both of these dialog outputs return a
as a result, which means using an if statement, the result can
be used to determine what events happen on each button.
Other output styles
There are other ways of outputting information such as directly putting the information on to the user interface through the use of a control such as a Label or ListBox.
- Create a program that displays the same sentence on both the console and on a dialog.