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 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.
|Provides an Abort, Retry or Ignore dialog|
|Designed to be in keeping with application style.|
|Shows the critical status and makes a Windows beep|
|Sets button 1 as the default button|
|Sets button 2 as the default button|
|Sets button 3 as the default button|
|Warns the user of a possible issue|
|Provides information using a dialog|
|Provides a Help button on the dialog|
|Right aligns the text in the dialog|
|Makes the dialog follow RTL (right-to-left) reading used by some countries|
|This message dialog will be in the foreground when created.|
|Provides a dialog with both Ok and Cancel buttons on it|
|Provides a dialog with just an Ok button it.|
|Provides the user with a question mark dialog.|
|A dialog with a Retry and a Cancel button.|
|Designed to be in keeping with the system style.|
|Provides simple Yes and No buttons.|
|Provides Yes, No and Cancel buttons|
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.
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.