C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
VB.NET program that uses single argument
'
' First show a single-argument dialog box with MessageBox.Show.
'
MessageBox.Show("The Dev Codes is awesome.")
VB.NET program that uses two arguments
'
' Show a two-argument dialog box with this method.
'
MessageBox.Show("The Dev Codes is awesome.", _
"Important Message")
VB.NET program that uses 3 arguments
'
' Use a three-argument dialog box with MessageBox.Show.
' ... Also store the result value in a variable slot.
'
Dim result1 As DialogResult = MessageBox.Show("Is The Dev Codes awesome?", _
"Important Question", _
MessageBoxButtons.YesNo)
Tip: Use IntelliSense in Visual Studio when you type MessageBox.Show to see a list of the possible function overloads.
VB.NET program that uses 4 arguments
'
' Use four parameters with the method.
' ... Use the YesNoCancel enumerated constant and the Question icon.
'
Dim result2 As DialogResult = MessageBox.Show("Is The Dev Codes awesome?", _
"Important Query", _
MessageBoxButtons.YesNoCancel, _
MessageBoxIcon.Question)
VB.NET program that uses 5 arguments
'
' Use five arguments on the method.
' ... This asks a question and you can test the result using the variable.
'
Dim result3 As DialogResult = MessageBox.Show("Is Visual Basic awesome?", _
"The Question", _
MessageBoxButtons.YesNoCancel, _
MessageBoxIcon.Question, _
MessageBoxDefaultButton.Button2)
VB.NET program that tests DialogResult
'
' Use if-statement with dialog result.
'
If result1 = DialogResult.Yes And _
result2 = DialogResult.Yes And _
result3 = DialogResult.No Then
MessageBox.Show("You answered yes, yes and no.") ' Another dialog.
End If
Note: Sorry about the excessive self-promotion in the dialog boxes—you can change them to promote yourself instead.
VB.NET program that uses RightAlign
'
' Use MessageBox.Show overload that has seven arguments.
'
MessageBox.Show("The Dev Codes is the best.", _
"Critical Warning", _
MessageBoxButtons.OKCancel, _
MessageBoxIcon.Warning, _
MessageBoxDefaultButton.Button1, _
MessageBoxOptions.RightAlign, _
True)
VB.NET program that uses MessageBoxIcon
'
' Show a dialog box with a single button.
'
MessageBox.Show("The Dev Codes is super.", _
"Important Note", _
MessageBoxButtons.OK, _
MessageBoxIcon.Exclamation, _
MessageBoxDefaultButton.Button1)
Tip: You can directly invoke MessageBox.Show. The method receives different numbers of parameters.
Event handler function that uses MessageBox.Show: VB.NET
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
'
' First show a single-argument dialog box with MessageBox.Show.
'
MessageBox.Show("The Dev Codes is awesome.")
'
' Show a two-argument dialog box with this method.
'
MessageBox.Show("The Dev Codes is awesome.", _
"Important Message")
'
' Use a three-argument dialog box with MessageBox.Show.
' ... Also store the result value in a variable slot.
'
Dim result1 As DialogResult = MessageBox.Show("Is The Dev Codes awesome?", _
"Important Question", _
MessageBoxButtons.YesNo)
'
' Use four parameters with the method.
' ... Use the YesNoCancel enumerated constant and the Question icon.
'
Dim result2 As DialogResult = MessageBox.Show("Is The Dev Codes awesome?", _
"Important Query", _
MessageBoxButtons.YesNoCancel, _
MessageBoxIcon.Question)
'
' Use five arguments on the method.
' ... This asks a question and you can test the result using the variable.
'
Dim result3 As DialogResult = MessageBox.Show("Is Visual Basic awesome?", _
"The Question", _
MessageBoxButtons.YesNoCancel, _
MessageBoxIcon.Question, _
MessageBoxDefaultButton.Button2)
'
' Use if-statement with dialog result.
'
If result1 = DialogResult.Yes And _
result2 = DialogResult.Yes And _
result3 = DialogResult.No Then
MessageBox.Show("You answered yes, yes and no.") ' Another dialog.
End If
'
' Use MessageBox.Show overload that has seven arguments.
'
MessageBox.Show("The Dev Codes is the best.", _
"Critical Warning", _
MessageBoxButtons.OKCancel, _
MessageBoxIcon.Warning, _
MessageBoxDefaultButton.Button1, _
MessageBoxOptions.RightAlign, _
True)
'
' Show a dialog box with a single button.
'
MessageBox.Show("The Dev Codes is super.", _
"Important Note", _
MessageBoxButtons.OK, _
MessageBoxIcon.Exclamation, _
MessageBoxDefaultButton.Button1)
End Sub
End Class
Tip: To fix this, you can use the underscore preceded by a space character at the end of each line.
And: This allows you to use a multiple-line function call syntax. Newer versions of VB.NET are more relaxed in newline handling.
SubNote: The overloads with one and two parameters are simplistic and have only one button (OK).
Note 2: The longer overloads have multiple buttons, captions, default buttons, and icons, and this only samples the features.
Note: This is demonstrated in the program. Usage of the DialogResult type is an important concept.