Anda di halaman 1dari 32

DEPARTMENT OF TECHNICAL EDUCATION

ANDHRA PRADESH
Name of the faculty : G. Radha
Designation : Lecturer
Branch : CCP
Institute : 026 - SG Govt. Polytechnic,
Adilabad
Year / Semester : III Year / V Semester
Subject : Visual Basic – I
Subject Code : CCP - 503
Topic : Understand Menus and Common
dialogue control .
Duration : 50 Mts.
Sub Topic : Common Dialogue Control.
Teaching Aids : Animations & Images

CCP-503.18 1
Recap
 Dialogue Boxes in Visual Basic.

CCP-503.18 2
Objectives :
Upon the completion of this period,
you will be able to understand about
 Predefined Dialogue Boxes.

CCP-503.18 3
Predefined Dialogue Boxes

Predefined Dialogue Boxes can be added


easily to an application in VB by using relevant
functions

 MsgBox() Function is used to add message box.

 InputBox() Function is used to add Input box.

 These Dialogue Boxes are always Modal Dialogue Boxes.

CCP-503.18 4
Design a small program with MsgBox()
function
 MsgBox() function is used to display messages on
the Form.

 A new Standard EXE Project is opened and the


Form and the Project files are saved as Dialog.frm
and Dialog.vbp.

 The Program is designed according to the property


table given below.

CCP-503.18 5
Design a small program with MsgBox()
function

Object Property Settings


Form Caption DISPLAY
FORM

Form Name Dialog

CCP-503.18 6
Design a small program with MsgBox()
function

Menu Items are added to the


Form as per the following table.

CCP-503.18 7
Design a small program with MsgBox()
function
Caption Name
&File MnFile

….D&isplay MnDisplay

- MnSep1

….E&xit MnExit

CCP-503.18 8
Design a small program with MsgBox()
function

CCP-503.18 9
Design a small program with MsgBox()
function
Private Sub MnDisplay_Click()
Dim Message As String
Dim DialogType As Integer
Dim Title As String
Message = "Have A Gala Shopping“
DialogType = vbOK + vbInformation
Title = "Welcome to the Super Market"
MsgBox Message, DialogType, Title
End Sub

CCP-503.18 10
Design a small program with MsgBox()
function

 The MnDisplay_Click procedure updates the three


variables Message, DialogType and Title that are
used as the parameters to the MsgBox statement
before Executing it.

 As a result a message box appears with VbOK and


VbExclamation which are VB constants that
represent the OK icon and Exclamation point icon.

CCP-503.18 11
Design a small program with MsgBox()
function

CCP-503.18 12
Design a small program with MsgBox()
function

The following code is entered in the


MnExit_Click() event procedure.

CCP-503.18 13
Design a small program with MsgBox()
function
Private Sub MnExit_Click()
Dim Message As String
Dim DialogType As Integer
Dim Title As String
Dim Response As Integer
Message = "Thank You, Visit Again"
DialogType = vbYesNo + vbInformation
Title = "Good Bye"
Response = MsgBox(Message, DialogType, Title)
If Response = vbYes Then
End
End If
End Sub
CCP-503.18 14
Design a small program with MsgBox()
function

CCP-503.18 15
Design a small program with MsgBox()
function
 The MnExit_Click procedure updates the variables
Message, DialogType and Title. Once these three
variables are updated MsgBox() function is executed
and its returned value is assigned to the variable
Response.
 The returned value of the MsgBox() function
indicates the button that was clicked.

CCP-503.18 16
Design a small program with MsgBox()
function
 The MsgBox() function takes the same parameters
as the MsgBox statement.

 The only difference between the MsgBox statement


and MsgBox() function is that the function returns a
value.

 The returned value indicates the button that was


clicked in the dialogue box.

CCP-503.18 17
Using InputBox() Function
 It displays a Modal Dialogue Box that asks the user
to enter some data.

 The Dialogue Box contains a message, an OK


button and Cancel button.

 The user can type in the Text Box and close the
Dialogue Box by clicking OK.

CCP-503.18 18
Syntax of InputBox() Function

InputBox(Message, Title)

For example :

I = InputBox(“Enter a Date :”, “Date Demo”)

CCP-503.18 19
Design a small program with InputBox()
function

Now we insert new Menu Items before Exit


Menu Item of the Display Program.

Caption Name

….Get&Date MnDate

….Get&Value MnValue

- MnSep2

CCP-503.18 20
Design a small program with InputBox()
function

CCP-503.18 21
Design a small program with InputBox()
function

The following code is entered in the event


procedure MnDate_Click().

CCP-503.18 22
Design a small program with InputBox()
function

Private Sub MnDate_Click()


DIM I as date string
DIM day as string
DIM Msg as string
I = InputBox("Enter a Date :", "Date Demo")
If Not IsDate(I) Then
MsgBox "Invalid Date"
Exit Sub
End If
Day = Format(I, "dddd")
Msg = "Day of this Date is :" + Day
MsgBox Msg
End Sub CCP-503.18 23
Design a small program with InputBox()
function

 Whenever GetDate Menu Item is clicked the code


in MnDate procedure asks the user to enter a
Date and verifies if Date is valid.
 An InputBox with a message, Enter a Date and
OK and Cancel button appears.

CCP-503.18 24
Design a small program with InputBox()
function

CCP-503.18 25
Design a small program with InputBox()
function
 If the Date is entered is a valid one such as
18/10/1974, the user is prompted with a message
box indicating the day of that date.

CCP-503.18 26
Summary
We have discussed about :

 Predefined Dialogue Boxes in Visual Basic,


Msg box and Input box

CCP-503.18 27
Quiz

CCP-503.18 28
1. ________ and _______ functions are used
to add predefined dialogue boxes.

A) InputBox() and MsgBox()


B) InputBox() and MsgBox Statement
C) MsgBox() and InputBox Statement
D) MsgBox() and OutputBox()

CCP-503.18 29
2. Predefined Dialogue Boxes are always ______
Dialogue Boxes.

A) Modeless Dialogue Boxes


B) Modal Dialogue Boxes
C) Custom Dialogue Boxes
D) Standard Dialogue Boxes

CCP-503.18 30
Frequently Asked Questions

1. Differentiate between MsgBox


Statement and MsgBox()
Function.

CCP-503.18 31
Assignment

1. Develop an application that asks a name


and shows it as a message

CCP-503.18 32

Anda mungkin juga menyukai