1 visual basic part i - a tool for customizing your program principles of gis 11-3-00
TRANSCRIPT
1
Visual Basic Part I - A tool for customizing your program
Principles of GIS11-3-00
2
OOP and structure programs
Structured programs - designed to solve one
big problem, subdividedinto smaller sections.
Object-oriented programs - break the problem downinto objects, each witha life of their own, with certain characteristics
(properties) andcertain functions that
it is able to perform (methods)
3
Opening of Visual Basic screen
1. Go to Start > Programs > Microsoft Visual Basic 5.0 > Visual Basic
2. Click on “OPEN” once you see the window shown below
4
Title bar Menu bar
Menu toolbar
Form
Code window
if you don’t get this, double-click on Form
toolbox
Properties window
Project explorer
5
The Toolbar
Add Project (on File menu)
Add item type
Menu editor
Open ProjectSave project
UndoRedo
Start
Break End
Project explorer
Properties window
Object browser
Toolbox
Form layout window
6
View > Toolbar (try this out)
DebugEditForm EditorStandardCustomize...
7
Form - central piece of the VB typical application is derived from
a Form Like an artist, VB programmers lay
down controls, such as command buttons, text boxes etc. on to the canvas - the form
Code - invisible to the users
8
Controls and the Toolbox
PointerLabelFrameCheckBoxComboBoxHScrollBarTimerDirListBoxShapeImageOLE
PictureTextBoxCommendButtonOptionButtonListBoxVScrollBoxDriveListBoxFileListBoxLineData
9
Run and save your project
10
Application Wizard
Click on Open after VB Application Wizard is selected
Click on “Next”
11
MDI and default menus1
2
3
4
12
Standard forms/Data access/ project name
13
Run and see what happens
14
Draw a circle and two lines
15
Form’s properties Try “ControlBox” turned to “False”
from “True” BorderStyle from “2-Sizable” to “1-
Fixed Single”
16
Code Each form has certain events
associated with it and the most important one is “Load” event. The “Load” event is triggered whenever a form is first loaded and just before it is displayed
Let’s try to create a simple program that places today’s date on the form
17
Label Control Drag a box after you select control
box from toolbox Run it and see what do you get
type in the statements shown here
StartupPosition - 2 Center on Screen
18
Run it again and see the display
Within “Unload” event, type in Msgbox “Goodbye!”Run it and see what happens when you close the window
19
Saving the project
20
Working with Controls Placing controls on the form
Click on “command button” from the toolbox (size it to the appropriate size and location on the form)
Go to “Tools/Options../General/Turn off the Grid”
Place one more and lock them by going to “Format/Lock Control” and now try to move it and see what happens
21
This is what you will get
22
Now we need to make the control working Three types of hook : 1) Properties: how control looks and
behaves, eg. people with height, weight... 2) Methods: all things that the control can
do, people can eat 3)Events: the things you can do to a
control that it will recognize and be able to respond to, eg. mouse over, click, down...
23
Make the control “beep” type in Beep i code
window as shown left
Click on “Start” or F5 and then “Enter”
Click on “Command 1” and you will hear
“Dong”
24
Caption The Caption Property: found on objects
such as forms, frames, and command buttons, is a piece of text that is displayed on screen to give the object some kind of header or title
Try to change the Caption of the command box to “Caption here”
Try this “&Change” and the hot key (C) will be underlined
25
Text Box and other exercise
Draw a text box from the toolbar and change the font to “Tahoma/10” (font name and size) BackColor to “desktop”
Change name to “txtDisplay” and “cmdChange” for command box
change the Multiline property of the text box from false to true.
change the Locked Property to True (you can’t type in any letters now)
Double click on the Change button and add the following line to the event code:
txtDisplay.Text=txtDisplay.Text + “Hello!”
26
Run the program and press the Change button and see what happens
This is what you get after pressing Change many times