Вы находитесь на странице: 1из 17

MENUS, SUB PROCEDURES AND SUB

FUNCTION

Nor Asma Mohd Zin


Introduction
Menu consist of a menu bar with menu names, each of
which drops down to display a list of a menu
commands
You can use menu command in place of or in addition
to command button
To use menu, select menu editor from the Tools menu
or click on the Menu Editor Toolbar button
Menu Caption

Menu name
Use prefix ‘mnu’ for menu

Menu
COMMON DIALOG BOXES

The common dialog control allow your project to use


the dialog boxes that are provided as part of the
Windows environment
Using a Common Dialog Box

To use the dialog box, you have to specify which box
you want using Show method
Object.ShowMethod
Dialog box Method
Open ShowOpen
Save As ShowSave
Color ShowColor
Font ShowFont
Print ShowPrint
Color Dialog Box

Private Sub mnuEditColor_Click()


With dlgCommon
.Flags = cdlCCRGBInit 'Initialize dialog
box

.Color = lblDispSubTotal.ForeColor
'Set initial color which is ‘first displayed on the palette

.ShowColor 'Display dialog box


lblDispSubTotal.ForeColor = .Color
lblDispTax.ForeColor = .Color
lblDispTotDue.ForeColor = .Color
End With
End Sub
Font Dialog Box

.SetFlag  cdlCFScreenFont, cdlCFPrinterFont


Font Object of Font Property of Values
Other Control Common Dialog
Control
Font.Bold FontBold True or False
(Boolean)
Font.Italic FontItalic True or False
(Boolean)
Font.Name FontName System
Dependent
Font.Size FontSize Font Dependent
Font.StrikeThro FontStrikeThru True or False
ugh (Boolean)
Font.Underline FontUnderline True or False
(Boolean)
Private Sub mnuFont_Click()
With dlgCommon
.Flags = cdlCFScreenFonts
.ShowFont
lblDispSubTotal.Font.Name = .FontName
lblDispTax.Font.Name = .FontName
lblDispTotDue.Font.Name = .FontName
End With

End Sub
SUB PROCEDURE

 Rather than retyping the same code, you can write


reusable code in a general procedure and call it from
both event procedures.

 General procedures are also useful in breaking down


large section of code into smaller unit that perform a
specific task.
Private sub SelectColor (lngIncomingColor As Long)
With dlgColor
.Flags = cdlCCRGBInit 'Initialize dialog box
.Color = lngIncomingColor 'Set initial color
which is first ‘displayed on the palette
.ShowColor 'Display dialog box

End With
End Sub
 
Prive Sub cmdChangeMessgase_Click()
Dim lngOriginalColor As Long

lngOriginalColor = lblMessgase.ForeColor
SelectColor lngOriginalColor
lblMessage.Forecolor = dlgColor.Color
End Sub
Passing Argument ByVal or ByRef
The ByVal sends a copy of the argiment’s value to the
procedure so that the procedure cannot change the original
value.
 ByRef sends a reference indicating where the value is stored
in the memory, allowing the called procedure to actually
change the argument’s original value.
You have to specify how you want to pass the argument,
ByVal or ByRef. If you don’t specify, arguments are passed
by reference.
A sub procedure is a procedure that performs actions.
A function procedure may perform an action but it also
returns a value (the return value) to the point from which it is
called.
 
Private Function curFindTax(curAmount As Currency)
As Currency
curFindTax = mcurTaxRate * curAmount
End Function
 

Вам также может понравиться