1 visual basic part i - a tool for customizing your program principles of gis 11-3-00

26
1 Visual Basic Part I - A tool for customizing your program Principles of GIS 11-3-00

Upload: ross-nicholson

Post on 18-Jan-2016

214 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: 1 Visual Basic Part I - A tool for customizing your program Principles of GIS 11-3-00

1

Visual Basic Part I - A tool for customizing your program

Principles of GIS11-3-00

Page 2: 1 Visual Basic Part I - A tool for customizing your program Principles of GIS 11-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)

Page 3: 1 Visual Basic Part I - A tool for customizing your program Principles of GIS 11-3-00

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

Page 4: 1 Visual Basic Part I - A tool for customizing your program Principles of GIS 11-3-00

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

Page 5: 1 Visual Basic Part I - A tool for customizing your program Principles of GIS 11-3-00

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

Page 6: 1 Visual Basic Part I - A tool for customizing your program Principles of GIS 11-3-00

6

View > Toolbar (try this out)

DebugEditForm EditorStandardCustomize...

Page 7: 1 Visual Basic Part I - A tool for customizing your program Principles of GIS 11-3-00

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

Page 8: 1 Visual Basic Part I - A tool for customizing your program Principles of GIS 11-3-00

8

Controls and the Toolbox

PointerLabelFrameCheckBoxComboBoxHScrollBarTimerDirListBoxShapeImageOLE

PictureTextBoxCommendButtonOptionButtonListBoxVScrollBoxDriveListBoxFileListBoxLineData

Page 9: 1 Visual Basic Part I - A tool for customizing your program Principles of GIS 11-3-00

9

Run and save your project

Page 10: 1 Visual Basic Part I - A tool for customizing your program Principles of GIS 11-3-00

10

Application Wizard

Click on Open after VB Application Wizard is selected

Click on “Next”

Page 11: 1 Visual Basic Part I - A tool for customizing your program Principles of GIS 11-3-00

11

MDI and default menus1

2

3

4

Page 12: 1 Visual Basic Part I - A tool for customizing your program Principles of GIS 11-3-00

12

Standard forms/Data access/ project name

Page 13: 1 Visual Basic Part I - A tool for customizing your program Principles of GIS 11-3-00

13

Run and see what happens

Page 14: 1 Visual Basic Part I - A tool for customizing your program Principles of GIS 11-3-00

14

Draw a circle and two lines

Page 15: 1 Visual Basic Part I - A tool for customizing your program Principles of GIS 11-3-00

15

Form’s properties Try “ControlBox” turned to “False”

from “True” BorderStyle from “2-Sizable” to “1-

Fixed Single”

Page 16: 1 Visual Basic Part I - A tool for customizing your program Principles of GIS 11-3-00

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

Page 17: 1 Visual Basic Part I - A tool for customizing your program Principles of GIS 11-3-00

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

Page 18: 1 Visual Basic Part I - A tool for customizing your program Principles of GIS 11-3-00

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

Page 19: 1 Visual Basic Part I - A tool for customizing your program Principles of GIS 11-3-00

19

Saving the project

Page 20: 1 Visual Basic Part I - A tool for customizing your program Principles of GIS 11-3-00

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

Page 21: 1 Visual Basic Part I - A tool for customizing your program Principles of GIS 11-3-00

21

This is what you will get

Page 22: 1 Visual Basic Part I - A tool for customizing your program Principles of GIS 11-3-00

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...

Page 23: 1 Visual Basic Part I - A tool for customizing your program Principles of GIS 11-3-00

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”

Page 24: 1 Visual Basic Part I - A tool for customizing your program Principles of GIS 11-3-00

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

Page 25: 1 Visual Basic Part I - A tool for customizing your program Principles of GIS 11-3-00

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!”

Page 26: 1 Visual Basic Part I - A tool for customizing your program Principles of GIS 11-3-00

26

Run the program and press the Change button and see what happens

This is what you get after pressing Change many times