VB Msgbox - MessageBox Function in Visual Basic 6

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

21/08/13

VB msgbox - MessageBox Function in Visual Basic 6

VB6 beginners tutorial Learn VB6 Advanced VB6 tutorial Learn Advanced VB6 Systems Analysis System analysis and Design tutorial for Software Engineering

You are he re :

Visual Basic > VB6 (Beginners Tutorial)

Previous Page | Table of Contents | Next Page

MessageBox Function In Visual Basic 6 (VB6)

Browse Topics
- Ge tting starte d - Data Type s - Module s - O pe rators in VB6 - VB6 Variable - VB6 Proce dure s - VB6 C ontrol Structure s - Loops in VB6 - VB6 Ex it Do & W ith End
W ith

- Arrays in VB6 - Use r-De fine d

Data Type s - VB6 C onstants - VB6 Built-in Functions - Date and Tim e in VB6

Displays a message in a dialog box and wait for the user to click a button, and returns an integer indicating which button the user clicked. Following is an expanded MessageBox

- VB6 C ontrols - Te x tBox C ontrol - C om boBox &


O ptionButton

- Labe l & Fram e - Picture Box & Im age Box - Tim e r C ontrol - ListBox & C om boBox - VB6 ScrollBar - C ontrol Arrays in VB6 - File s controls in VB6 - VB6 C he ck Box - Form s in VB6 - Me nus in VB6 - MDI Form in VB6 - InputBox - Me ssage Box - Mouse e ve nts - Mouse Move - Error Handling - Error Handling (2) - VB6 Database

Syntax : MsgBox ( Prompt [,icons+buttons ] [,title ] ) memory_variable = MsgBox ( prompt [, icons+ buttons] [,title] ) Prompt : String expressions displayed as the message in the dialog box. If prompt consist of more than one line, you can separate the lines using the vbrCrLf constant. Icons + Buttons : Numeric expression that is the sum of values specifying the number and type of buttons and icon to display. Title : String expression displayed in the title bar of the dialog box. If you omit title, the application name is placed in the title bar. Icons Constant vbCritical vbQuestion vbExclamation vbInformation Buttons Constant vbOkOnly vbOkCancel vbAbortRetryIgnore vbYesNoCancel vbYesNo vbRetryCancel Value 0 1 2 3 4 5 Description Display OK button only Display OK and Cancel buttons Display Abort, Retry and Ignore buttons Display Yes, No and Cancel buttons Display Yes and No buttons Display Retry and Cancel buttons Value 16 32 48 64 Description Display Critical message icon Display Warning Query icon Display Warning message icon Display information icon

visualbasic.freetutes.com/learn-vb6/lesson18.html

1/3

21/08/13

VB msgbox - MessageBox Function in Visual Basic 6

Return Values Constant vbOk vbCancel vbAbort vbRetry vbIgnore vbYes vbNo Value 1 2 3 4 5 6 7 Ok Button Cancel Button Abort Button Retry Button Ignore Button Yes Button No Button Description

Following is an example illustrates the use of message boxes * Open a new Project and save the Form as messageboxdemo.frm and save the Project as messageboxdemo.vbp * Design the application as shown below. Object Form Property Caption Name Setting MessageBoxDemo frmMessageBoxDemo

Label

Caption Name

lblName Name txtName ( empty ) lstName Add cmdAdd

TextBox

Name Text

ListBox CommandButton

Name Caption Name

CommandButton

Caption Name

Delete cmdDelete

CommandButton

Caption Name

Exit cmdExit

Following code is entered in the txtName_Change ( ) event P r i v a t eS u bt x t N a m e _ C h a n g e ( ) I fL e n ( t x t N a m e . T e x t )>0T h e n c m d A d d . E n a b l e d=T r u e E n dI f E n dS u b Following code has to be entered in the cmdAdd_Click ( ) event P r i v a t eS u bc m d A d d _ C l i c k ( ) a n s w e r=M s g B o x ( " D oy o uw a n tt oa d dt h i sn a m et ot h el i s tb o x ? " ,v b E x c l a m a t i o n+v b Y e s N o , " A d dC o n f i r m " ) I fa n s w e r=v b Y e sT h e n

visualbasic.freetutes.com/learn-vb6/lesson18.html

2/3

21/08/13

VB msgbox - MessageBox Function in Visual Basic 6


I fa n s w e r=v b Y e sT h e n l s t N a m e . A d d I t e mt x t N a m e . T e x t t x t N a m e . T e x t=" " t x t N a m e . S e t F o c u s c m d A d d . E n a b l e d=F a l s e E n dI f E n dS u b Following code is entered in the cmdDelete_Click ( ) event P r i v a t eS u bc m d D e l e t e _ C l i c k ( ) D i mr e m o v eA sI n t e g e r r e m o v e=l s t N a m e . L i s t I n d e x I fr e m o v e<0T h e n M s g B o x" N on a m e si ss e l e c t e d " ,v b I n f o r m a t i o n ," E r r o r " E l s e a n s w e r=M s g B o x ( " A r ey o us u r ey o uw a n tt od e l e t e"&v b C r L f&" t h es e l e c t e dn a m e ? " , _ v b C r i t i c a l+v b Y e s N o ," W a r n i n g " ) I fa n s w e r=v b Y e sT h e n I fr e m o v e> =0T h e n l s t N a m e . R e m o v e I t e mr e m o v e t x t N a m e . S e t F o c u s M s g B o x" S e l e c t e dn a m ew a sd e l e t e d " ,v b I n f o r m a t i o n ," D e l e t eC o n f i r m " E n dI f E n dI f E n dI f E n dS u b Following code is entered in the cmdExit_Click ( ) event P r i v a t eS u bc m d E x i t _ C l i c k ( ) a n s w e r=M s g B o x ( " D oy o uw a n tt oq u i t ? " ,v b E x c l a m a t i o n+v b Y e s N o ," C o n f i r m " ) I fa n s w e r=v b Y e sT h e n E n d E l s e M s g B o x" A c t i o nc a n c e l e d " ,v b I n f o r m a t i o n ," C o n f i r m " E n dI f E n dS u b Save and run the application. You can notice the different type of message box types are used to perform an action ( Download the source code )

Previous Page | Table of Contents | Next Page

Home | Link to Us | About Us | Privacy Policy | Contact Us Copyright Freetutes.com | All Rights Reserved

visualbasic.freetutes.com/learn-vb6/lesson18.html

3/3

You might also like