Usage of MsgBox
Divide functions and sentences, first discuss sentences
form
MsgBox (Prompt [,Buttons] [,Title] [,Helpfile,Context])
Promt
required. String expression. The message is displayed. The maximum length is 1024 characters. Line break (Chr(13) & Chr(10))
Private Sub Form_Load()
MsgBox "welcome" & Chr(10) & Chr(13) & "hello world"
End Sub
Button:
Button type:
Symbolic constant | value | effect |
---|---|---|
VBOkOnly | 0 | Only show the'OK' button |
VBOKCancle | 1 | Only show the'OK' and'Cancel' buttons |
vbAbortRetryIgnore | 2 | Show'discard','retry' and'ignore' buttons |
vbYesNoCancel | 3 | Show'yes','no' and'cancel' buttons |
VBYesNo | 4 | Show'yes' and'no' buttons |
VBRetryCancel | 5 | Show'retry' and'cancel' buttons |
Private Sub Form_Load()
MsgBox "welcome" & Chr(10) & Chr(13) & "hello world", 4
End Sub
Icon form:
Symbolic constant | value | effect |
---|---|---|
VBCritical | 16 | Show system cross icon |
VBQuestion | 32 | Show system question mark icon |
vbExclamation | 48 | Show system exclamation mark icon |
vbInformation | 64 | Show system information icon |
Private Sub Form_Load()
MsgBox "welcome" & Chr(10) & Chr(13) & "hello world", 16
End Sub
Default button:
Symbolic constant | value | effect |
---|---|---|
VBDefaultButton1 | 0 | The first button is the default button |
VBDefaultButton2 | 256 | The second button is the default button |
VBDefaultButton3 | 512 | The third button is the default button |
VBDefaultButton4 | 768 | The fourth button is the default button |
Private Sub Form_Load()
MsgBox "welcome" & Chr(10) & Chr(13) & "hello world", 256
End Sub
Not enough buttons, the default is the first button
Mandatory return:
Symbolic constant | value | effect |
---|---|---|
VBApplicationModal | 0 | Application forced to return |
VBSystemModal | 4096 | System forced return |
If you define the button type and icon style at the same time, you can add the two values together.
Private Sub Form_Load()
MsgBox "welcome" & Chr(10) & Chr(13) & "hello world", 49
End Sub
Title
Show content in title box
Private Sub Form_Load()
MsgBox "welcome" & Chr(10) & Chr(13) & "hello world", 49,"Door"
End Sub