KEMBAR78
Unit 2 VB | PDF | Menu (Computing) | Keyboard Shortcut
0% found this document useful (0 votes)
27 views58 pages

Unit 2 VB

Uploaded by

Rajashree B
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views58 pages

Unit 2 VB

Uploaded by

Rajashree B
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 58

UNIT -II

• Menubar is placed at the top of the window.


The standard form is displayed without
menus, but the user can add it.
• To create menu -three ways:
1- Press menu icon from toolbar .
2- press (ctrl+E) from keyboard.
3- click on: tools -> Menu Editor.
Sub Menus
MENU Editor
Steps to create Menus
Creating Menu Command Lists

create menus and then add them to Program menu bar.

To create a list of menu commands on a form


• On toolbar, click the Menu Editor icon, or select
Menu Editor from the Tools menu.
• In Caption, type the menu caption (the name that will
appear on the menu bar)
• In the Name text box, type the menu name
,programmers use the mnu object name prefix to
identify both menus and menu commands.
• To add the menu to your program menu bar,
click Next.
• Click the right arrow button in the Menu
Editor dialog box to move items to the right
and click the left arrow button to move items
to the left.
• Click Next and continue to add options to your
menu.
Access and Shortcut Keys
• Access key : Letter the user can press to execute the
command when the menu is open.

• Prefix the access key letter in the menu item caption


with an ampersand (&).

• Shortcut key : key combination the user can press to


run the command without opening the menu

• Pick a key combination from the Shortcut drop-down


list box.
Disabling a Menu Command
• All menus are not available at the same time.
• For example, the Paste command is available
only when there is data copied on Clipboard.
When a command is disabled - dimmed (gray)
– Clearing the Enabled check box for that
menu item in the Menu Editor.
– Using code to Enable property to False.
(When you’re ready to use the menu
command again, set its Enable property to
True.)
POPUP MENUS
• Popup menus are generally invoked by right-
clicking the mouse button.
• Based on the location of the mouse,
applications will display a specific menu.
• VB provides a Popup menu method to show
the popup menu on forms surface.
• To use the Popup menu, create a menu, create
a menu with the name "View". See the
example given below.
SYNTAX :
PopupMenu Menuname, [Flags], [X], [Y],[DefaultMenu]

Example:

Private Sub Form_MouseDown()


If Button = vbRightButton Then
PopupMenu mnuView
End If
End Sub
Make the menu View as invisible
• https://www.youtube.com/watch?v=Ue8s_EJg
gaw
Creating Dialog Boxes
• There are many built-in dialog boxes to be used in
Windows forms for various tasks like opening and
saving files, printing a page, providing choices for
colors, fonts, page setup, etc., to the user of an
application. These built-in dialog boxes reduce the
developer's time and workload.
• A dialog box is simply a form in a program that
contains input controls designed to receive
information.
• To make your programming faster, Visual Basic
includes an ActiveX control, named Common Dialog.
• With this control, you can easily display six
standard dialog boxes in your programs.
• These dialog boxes handle routine tasks such
as opening files, saving files, and picking
fonts.
• If the dialog box you want to use is not
included in this ready-made collection of
objects, you can create a new one by adding a
second form to your program
• All of these dialog box control classes inherit
from the Common Dialog class
Types of Dialog Boxes
• Pre-Defined Dialog Boxes
• Custom Dialog Boxes
• Common Dialog Boxes
Pre-Defined Dialog Boxes
MsgBox ( ) Function
• MsgBox is to produce a pop-up message box that prompt the
user to click on a command button
X =msgbox(Prompt,Style Value, Title)
Style Value Named Constant Buttons Displayed
0 vbOkOnly Ok button
1 vbOkCancel Ok and Cancel buttons
2 vbAbortRetryIgnore Abort, Retry and Ignore buttons.
3 vbYesNoCancel Yes, No and Cancel buttons
4 vbYesNo Yes and No buttons
5 vbRetryCancel Retry and Cancel buttons
16 vbCritical Displays Critical Message icon.
32 vbQuestion Displays Warning Query icon
48 vbExclamation Displays Warning Message icon
64 vbInformation Displays Information Message icon
msgbox() Examples
• testmsg = msgbox("Click to test", 1, "Test
message")

• Another Example:
The InputBox( ) Function
• An InputBox( ) function will display a message box where the
user can enter a value or a message in the form of text. The
format is
• msg=InputBox(Prompt, Title, default_text, x-position, y-
position)
• Prompt - The message displayed normally as a question asked.
• Title - The title of the Input Box.
• default-text- The default text that appears in the input field where
users can use it as his intended input or he may change to the
message he wish to key in.
• x-position and y-position - the position or the coordinate of the
input box.
Example for Inputbox()
• userMsg = InputBox(“Enter Student’s Date of Birth”)

• userMsg = InputBox("What is your message?", "Message


Entry Form", "Enter your message here", 500, 700)
To add the Common Dialog control
to the toolbox
1. From the Project menu, click Components.
2. Click the Controls tab.
3. Don’t select Selected Items Only
4. select Microsoft Common Dialog Control, and then
click OK.
Common Dialog Control
Font and File Dialog Box
• ColorDialog
It represents a common dialog box that displays available colors along
with controls that enable the user to define custom colors.
• FontDialog
It prompts the user to choose a font from among those installed on the
local computer and lets the user select the font, font size, and color.
• OpenFileDialog
It prompts the user to open a file and allows the user to select a file to
open.
• SaveFileDialog
It prompts the user to select a location for saving a file and allows the user
to specify the name of the file to save data.
• PrintDialog
It lets the user to print documents by selecting a printer and choosing
which sections of the document to print from a Windows Forms
application.
Project- Components
• https://www.youtube.com/watch?v=hffnARqF
QiY
Private Sub Command1_Click()
Dim Value1 As Integer
Dim Value2 As Integer
Value1 = 12
Value2 = 0
Form1.Print Value1 / Value2
End Sub
Error Message
Error Handlers in VB
• A Visual Basic Error Handler can be coded in
each procedure if we want to find an error.
• If an error (any error at all) occurs in that
procedure, Visual Basic skip to code in the
Error Handler, and execute code.
• If no error occurs in the procedure, then
Visual Basic will execute the normal code.
Error Handler Message
Private Sub Command1_Click()
On Error GoTo errpart
Dim Value1 As Integer
Dim Value2 As Integer
Value1 = 12
Value2 = 0
Form1.Print Value1 / Value2
errpart:
MsgBox "Error Number:" & Err.Number & vbCrLf & Err.
Description Resume Next
End Sub
Breakpoints
• Break Points Since moving one step at a time can be painful,
there is another debugging tool available called “breakpoint.”
• When you run a program, the execution stops at the selected
line and you can check the values.
• Visual basic shows a large brown dot in the margin to remind
that there is a breakpoint in that line.
• For example if you wanted to check the volume calculation,
you would put a breakpoint in the line for volume calculation.
• You can put a breakpoint by clicking in gray area in the left of
the code. If you click once you will see red DOT, which
indicates breakpoint.
• To clear the breakpoint, simply click on the DOT again. When
you run the code, it will stop at the line where a breakpoint is
placed. You can use multiple breakpoints in a code.
Watch Windows
• A watch is a variable or expression that has been
placed in the window to enable you to monitor its
value.
• Lets you watch the values of variables and
expressions as your code executes.
• When your application enters break mode, the
watch expressions you select appear in a window
allowing you to observe their values etc.
• It is also possible to set up conditional watches.
This window is automatically updated after each
line of code is executed.
Immediate Window
• The Immediate window is extremely useful and allows you to test and
execute small snippets of code.
• This can be used for executing VBA statements directly, testing statements
and helping to debug your code
• The immediate window is particularly useful for testing variables or
properties.
• The Immediate window can be dragged and positioned anywhere on your
screen unless you have made it a dockable window from the Docking Tab
of the Options dialog box.
• You can close the window by clicking the Close box. If the Close box is not
visible, double-click the Title bar to make the Close box visible, then click
it.
• (View > Immediate Window)
Shortcut key (Ctrl + G).

You might also like