[Tutorial :: Message Box:: __Doc_]
This is a small tutorial/code snippet of the most basic of basic message boxes in VB6. Very useful for many things.

MsgBox ( Prompt [,icons+buttons ] [,title ] )

First lets start off with the basic message box function.
MsgBox " Hi I'm a Box! "
As you see MsgBox is called and the content is, " Hi I'm a Box! ". Very simple.
Let's get a little more complicated. Notice i didn't use () that's because my code isn't split and it doesn't have any extras in it.
Example of ()
MsgBox (txtUser & " Is Invalid") 'txtUser is our text box name
That allows me to have more that one "" within a string. Now in some cases () isn't needed you can just get by with ""
Now I'll show you something a little more professional. Say the user did something wrong and you need to tell them that and get their attention.
Example::
If txtUser = vbNullString Or Len(txtUser) = 0 Then
MsgBox " Please Enter a User Name", vbCritical, " Program Name Here "
Else MsgBox ("Thank You " & txtUser & " Is Valid")
End If
That code will check if txtUser = vbNullString or Nothing, Or the Length (len) of txtUser is equal to 0. If it is then open a msgbox with a Critical sound and image telling the user that they need to enter a username to proceed. If txtUser doesn't meet those requirements, then ELSE msgbox, Thanks.
You can use any , , you want. from vbCritical to vbYesNo, vbYesNoCancel, vbOkOnly ect ect.
A list of a few constants
Constant
Value
Description
vbCritical
16
Display Critical message icon
vbQuestion
32
Display Warning Query icon
vbExclamation
48
Display Warning message icon
vbInformation
64
Display information icon
vbOkOnly
0
Display OK button only
vbOkCancel
1
Display OK and Cancel buttons
vbAbortRetryIgnore
2
Display Abort, Retry and Ignore buttons
vbYesNoCancel
3
Display Yes, No and Cancel buttons
vbYesNo
4
Display Yes and No buttons
vbRetryCancel
5
Display Retry and Cancel buttons
vbOk
1
Ok Button
vbCancel
2
Cancel Button
vbAbort
3
Abort Button
vbRetry
4
Retry Button
vbIgnore
5
Ignore Button
vbYes
6
Yes Button
vbNo
7
No Button
Example::
If MsgBox("Is the word BLUE a colour?", vbYesNo, "Test") = vbYes Then
MsgBox "Well I'll be damned, you're not retarded, GTFO.", vbInformation, "Test Passed"
Else ' It could only be vbNo if it's not vbYes
MsgBox "Yeah, you're fucking retarded.", vbCritical, "Durr"
End If
As you see we used, vbYesNo. That will prompt two buttons, Yes and No. That gives the user an option to do more things with the msgbox. Here is another example of the vbYesNo
Dim reply As String
reply$ = MsgBox("MESSAGE HERE", vbInformation + vbYesNo)
If reply$ = vbYes Then
Form2.Show
Else
Exit Sub
End If
Now say you want a msgbox with a lot of text, but when you type on big line the box just gets longer and longer and longer. You don't want that. You want a nice sized box with all your text. Simple, we just use the vbCrLf or vbNewline. Here is a small example of a msgbox that you would have in Form_Load()
Private Sub Command1_Click()
MsgBox " Welcome to my program" & vbCrLf & _
" Version: 1 " & vbCrLf & _
" Author: __Doc_ " & vbCrLf & _
" Website: innovative-coding.com " & vbCrLf & _
" Thanks ", vbInformation, " Welcome To MY Program "
End Sub
Small compact, Shows all your information with the information image.
With a combination of these commands the options are limitless. Enjoy
 
# 1337
Message Box Tutorial :: by __Doc_