Visual Programming - PDF
Visual Programming - PDF
1. Standard
2. Professional
3. Enterprise
Features of Visual Basic
The main features of Visual Basic are as follows:
Click on start Programs Microsoft Visual Studio 6.0 Microsoft Visual Basic 6.0
Standard E X E
Shape Line
Image Data
OLE
Steps in building a Visual Basic Application
• Designing part :
• Coding part:
• Execution part:
•Assignment find the
average of two numbers ?
UNIT -2
Value Description
• Show Method:
• Show method is used to display a form.
• If the form is not loaded, the show method loads the
form firs and hen displays it.
• FormName is the name of the form and mode which
is optional.
• Mode can take values:
0 – Modeless(default)
1 - Modal
• 1 - Modal – A Modal Form is one that does
not allow the application to proceed unless the
form is closed.
• Ex: When a MsgBox is displayed in a modal
Window, it does not allow the user to proceed
until the user clicks on one of the
buttons(default – ok button). Or
form2.show(1)
• 0 - Modeless – Modeless Forms are highly
interactive. They allow the user to switch to
any of its other forms during execution.
Hide Method FromName.Hide
• When an application contains many forms, it is necessary
to hide some of them.
• Hide method only removes the Form from the screen, but
does not unload it from memory.
• Ex: Form2.hide
Form2.Caption=“Hidden Form”
Form2.Show
• Other methods :
➢ Cls : 1. This method is used to clear the form.
2. Cls method does not clear controls
3. But it clears any information printed or
drawn on the form using the print
statement.
FormName.Cls
ToolBox Controls
• ToolBox Controls contain all custom controls needed
for Visual Basic application.
Example 1:
• txtExample.SetFocus ' moves cursor to box
named txtExample
Example 2:
0 – Standard
1 – Graphical
• Back Color – Back color of a command botton takes effect,
only when the style property is set to graphical.
DragOver Keyup
MouseUp
Gotfocus LostFocus
• Command Button Methods.
• The most frequently used method is SetFocus.
Method Description
Set focus
Drag Refresh
Move Zorder
Check Box Control
1. In a group single control more than one 1. In a group only one option can be
control can be selected. selected.
Picture1.picture=LoadPicture(“D:\VBProject\Pics\lilly.Jpg”)
File Description
ListIndex The number of the most recently selected item in list. If no item is selected,
ListIndex = -1.
MultiSelect Controls how items may be selected (0 -none multiple selection not allowed,
1-multiple selection allowed, 2 - group user to extend the selection).
Sorted True means items are sorted in 'Ascii' order, else
items appear in order added.
Selected Array with elements set equal to True or False, depending on whether
corresponding list item is selected.
• List Box Events:
• Examples
lstExample.AddItem "This is an added item" ' adds text
string to list
lstExample.Clear ' clears the list box
lstExample.RemoveItem 4 ' removes lstExample.List(4)
from list box
• List Box Methods:
List1.AddItem “Lesson1”
List1.AddItem “Lesson2”
List1.AddItem “Lesson3”
List1.AddItem “Lesson4”
End Sub
Difference between an Combo Box and List
box control
Combo Box List Box
1. It occupies less space on the screen. 1. It occupies more space on the screen.
2. Instead of selecting an item user can 2. The user must select an item from the
type the text on to it. given list only.
• Frame Methods
Set focus
Drag Refresh
Move Zorder
Line Tool
Max The value of the horizontal scroll bar at the far right and the
value of the vertical scroll bar at the bottom. Can range from
-32,768 to 32,767.
Min The other extreme value - the horizontal scroll bar at the left
and the vertical scroll bar at the top. Can range from -32,768
to 32,767.
SmallChange The increment added to or subtracted from the scroll bar
Value property when either of the scroll arrows is clicked.
Value The current position of the scroll box (thumb) within the
scroll bar. If you set this in code, Visual Basic moves the
scroll box to the proper position. End arrow Scroll box
(thumb) Bar area.
Scroll Bar Events:
• The timer tool does not appear on the form while the
application is running.
Sub TimerName_Timer()
..
End Sub
This is where you put code you want repeated every
Interval seconds.
Drive List Box
• The drive list box control allows a user to select a
valid disk drive at run-time.
Menu title
Menu control
list box
Separator bar
• Properties:
• The Caption box is where you type the text that appears
in the menu bar.
• The right and left arrows adjust the levels of menu items,
while the up and down arrows move items within the
same level.
• The Next, Insert, and Delete buttons are used to
move the selection down one line, insert a line above
the current selection, or delete the current selection,
respectively.
Advanced Controls.
OR
Example:
Text1.Font = CommonDialog1.FontSize
Properties Description
CancelError If True, generates an error if the Cancel button is clicked.
Allows you to use error- handling procedures to recognize that
Cancel was clicked.
DialogTitle The string appearing in the title bar of the dialog box. Default
is Open. In the example, the DialogTitle is Open Example.
FileName Sets the initial file name that appears in the File name box.
After the dialog box is closed, this property can be read to
determine the name of the selected file.
Filter Used to restrict the filenames that appear in the file list box.
Complete filter specifications for forming a Filter can be found
using on- line help. In the example, the Filter was set to allow
Bitmap (*.bmp), Icon (*.ico) , Metafile (*.wmf) , GIF (*.gif) ,
and JPEG (*.jpg) types (only the Bitmap choice is seen).
• Open.bmp
• Save.bmp
• Print.bmp
• Help.bmp
At this point, click OK to dismiss the Property Pages
dialog.
• 6. The next order of
business is to bring the
toolbar control onto the
form. Do so by double-
clicking the Toolbar
control on the toolbox.
Syntax:
• Load object(Index %)
• To unload the control
• Unload object(index %)
Ending an Application
• Do not use END any longer
• Unload all loaded forms instead
– SDI - Unload Me for command button or menu
– MDI - Use For Each Next to unload forms
Private Sub Form_Unload(Cancel as Integer)
Dim SingleForm as Form
For Each SingleForm in Forms
Unload SingleForm
Next
End Sub
MDI
Interface Styles
• Multiple Document Interface (MDI)
• Single Document Interface (SDI)
Multiple Document Interface
Parent
Form
Child
Form
Child
Form
Single Document Interface
Independent
Form
Independent
Form
MDI versus SDI
• SDI=Single-Document Interface
– All we have created thus far
– Each form is in a separate window
• MDI=Multiple-Document Interface
– Like Word, Excel, etc.
– Forms display within the window of other forms
MDI (Multiple-Document Interface)
• One Parent window which "contains" other windows.
• Window menu
– Tile, Cascade, and Window List
Creating MDI Projects
• Add MDI form to project
– Project menu, Add MDI form