Library tutorials & articles
MsgBox Function
Usage
To show a OK dialog with a question mark you would type vbOKOnly+vbQuestion in the Buttons+Icon Parameter. The Dialog Title is a string which contains the title text. If this parameter is left blank, then the project name is used as the the Message Box's title
Msgbox "Are you sure?", vbYesNo+VBQuestion, "Front Page"
This shows a message box asking 'Are you sure' with yes and no buttons and a question icon. The Message Box function returns a number which tells you what button was pressed. The following constants are used:
| Constant | Button |
| vbOK | OK Button |
| vbYes | Yes Button |
| vbNo | No Button |
| vbAbort | Abort Button |
| vbRetry | Retry Button |
| vbCancel | Cancel Button |
| vbIgnore | Ignore Button |
Dim Ans As Integer
Ans = Msgbox("Are you sure?", vbYesNo+vbExclamation , "Front
Page")
If Ans = vbYes Then
Msgbox "You clicked yes"
Else
Msgbox "You clicked no"
End If
This displays a message box asking 'Are you sure?', with yes and no buttons and a exclamation mark. If you click yes, then another message box is displayed saying 'You clicked yes', otherwise it displays a message saying 'You clicked no'.
If you want to include a variables contents in any of the parameters you can use an ampersand (&).
TheText = Text1.Text
Msgbox "The contents of Text1 is" & TheText
---OR---
Msgbox "The contents of Text1 is" &
Text1.Text
Related articles
Related discussion
-
Run-time error '91'
by converter2009 (1 replies)
-
VB6 Runtime error 381 subsript out of range Error
by Uncle (2 replies)
-
passing and reading parameters from using Shell
by jigartoliya (0 replies)
-
Convert C++ code to VB6
by mawcot (4 replies)
-
listbox scrollbar
by Dennijr (10 replies)
Related podcasts
-
Christian Beauclair
14 mai 2008 (�mission #0074) ::.Christian Beauclair: Stratégies de migration VB6 vers .NET Nous discutons avec Christian Beauclair des stratégies de migration VB6 vers .NET. Entre autres, nous discutons comment utiliser le "VB 6 Code Advisor" et le "Interop Forms Toolkit" pour ajouter la puiss...
hi,
is it possible to have something which will display the information (information is one or two lines of text) for few seconds and disappear. if i use msgbox for it, there are many message boxes in the application which becomes annoying to the user.
do i have to create a new form for it or there is another function.
thanx in advance,
bye
Hello
dear i dont know how i can add icons in menu bar in visual basic .
plaease help me to solve this problem.
khuram
No, you need to make a new form that looks like a message box for that.
Dim ans As String
ans = MsgBox("Would you like to save changes?", vbYesNoCancel)
If ans = vbYes Then
'Put your Yes commands in here
Else
If ans = vbNo Then
'Put your No commands in here
Else
'Put your Cancel commands in here
End If
End If
if msgbox("Do you want to save changes",vbyesnocancel)=vbyes then
' saving document
Else
' could be EITHER CANCEL OR NO
End if
can you see the problem?
I am not an expert infact im only 13 however i have been doing vb for about 2 years and i have sure done a lot with the msgbox() function and i do remember reading somewere that you cannot add or remove buttons from the default messages that vb has already installed for you, however if you build yourown msgbox the possibilities are endless you can even add images and movies and anything u can think of , the easiest and lamest way to do this is to make a new form and call it say........"Message1" make 2 Buttons (Command1 and Command2) and make the "Message1" default BorderStyle
03 - Fixed Dialog then it will look like a normal window then u can manually set the height and width to whatever u like and then just have tha application load the "Message1" form whenever u need the message box and actually those types of message boxes are the easiest to code for desisions like if u have "ya" and the user clicks it u just code the Command1 for "ya" and command2 for "Tidak"
THAT SHOULD WORK!!!!
if it doesnt send me an email at Fruit_Cake70@hotmail.com
good luck with your application
Example I want to add:
button vbYa (which is in Malay) and the button caption is "Ya" (equal to Yes in English)
button vbTidak (in Malay) and the caption is "Tidak" (equal to No in English)
it's about changing the msgbox caption into my own Language.
thanks
I'm fairly new to VB but picking it up quite well.
Can I use custom buttons in a MsgBox? Like, if I want 'Fred', 'Bob' and 'Cancel'.
Button2 would be for no and Button3 is for cancel...
Msgbox "Do you want to save changes?", vbYesNoCancel+vbExclamation+vbDefaultButton3 , "Front Page"
would set the default button as No.
vbDefaultButton3 is the button for No? Is button2 for cancel? Would we want the user to cancel if they accidently pressed enter so they would make the choice of yes or no?
I am new so bear with me! Thanks.
This thread is for discussions of MsgBox Function.