Introduction to Visual Basic

Document Sample
Introduction to Visual Basic Powered By Docstoc
					Programming in Visual Basic 6.0

Chapter 1
Introduction to Visual Basic

Introduction to Visual Basic • Objective: Writing windows applications with Visual Basic • Programming languages: Language for communicating with a computer
– Machine Code (Machine Language) – Assembly Language – High Level Language

• The VB environment • Writing your first VB project • Finding & fixing errors

Definitions and Terms • • • • Program/Programmer User Algorithm See p. 12-13
Disk File Directory Folder Subfolder Filename Path Root Folder

• Graphical User Interface (GUI) • Point, Click, Double-Click, Hover

Graphical User Interface • Visual Basic allows you to create GUIs

• Graphic User Interface (GUI) comprises
– Forms – Controls – Event-driven programming

• Revolutionized the Computer Industry • Allows input forms or boxes…much friendlier interface

Writing Windows Applications with Visual Basic • The Windows GUI


Text boxes

Frame Option buttons

Check boxes

Command buttons

Picture box

Graphic User Interface

• Controls: The responsive objects a programmer places on a window • These objects recognize user actions such as mouse movements and button clicks • A good analogy: For Example
– Objects (nouns) – Properties (adjectives) – Methods (verbs) Option button What it looks like What it does

Planning Visual Basic Projects

• The three-step process for planning projects (p. 21)
– Design the user interface
Sketch the screens with forms and controls needed

– Establish the objects' properties
Write down the properties for each object

– Plan the Basic code
Write out pseudocode for actions your program will perform

Writing Visual Basic Projects

• The three-step process for writing projects
– Design the user interface
Create the forms and controls you previously sketched

– Set the objects' properties
Give each object a name and set their properties

– Write the Basic code
Write out Visual Basic code to carry out your application's actions

When the Program is Running

• Visual Basic monitors the controls in the window to detect any event (click, for example)
• When events detected, examine program to see if there’s a procedure associated with it • If there is a procedure, execute it • If there is no procedure, wait for the next event

The Visual Basic Environment • Form, Project Explorer, Properties, and Form Layout Windows • Toolbox • Main Visual Basic window • Toolbar, Form location & size information • Help • Design- , Run- …

The Toolbox • Tool box contents vary based on which version of Visual Basic you are running. • Toolbox contains a common set of tools across all VB versions • Visual Basic Toolbar:
– The buttons on the toolbar are shortcuts – Toolbar buttons are a quick way to activate frequently used commands – Each button stands for a command that you can also select a the Visual Basic menu

Writing Your First VB Project • • • • • • Set up your Visual Basic workspace Define user interface Set properties Write code Visual Basic code statements Run, save, open, modify, & print the Hello World project • Documentation

Set Up Your VB Workspace • Set up Options to reflect these settings:

Define the User Interface • Resize the form
– Drag the lower-right handle to enlarge the form – Drag any handle in the middle of a side to enlarge the form in that direction only

• Place controls on the form
– Click the label tool – Click and drag the mouse (a crosshair) to place the control on the form

Set Properties • Set the Name and Caption properties
– Always set the Name property before writing code – Next, set the Caption property

• The Name property identifies the object internally--so you can refer to it in code • The Caption property externally idenfities an object

Write Code • You write code enclosed in event procedures, which respond to typical VB events.
Private Sub cmdPush_Click() . . . (your code goes here) End Sub

• VB automatically supplies the event procedure Sub/End Sub statements

Visual Basic Code Statements • Remark statement is any code line beginning with an apostrophe • Assignment statement • End statement

Run/Save/Open/Modify the Project • Test the project:
– Click Run, Start (or click the Start button on the toolbar) – Click the Push Me button – Click the Exit button

• Save the project and the form • Make modifications to the form • Print the project documentation:
– Form Image, Code, and Form as Text

Finding & fixing errors • • • • Compile (syntax) errors Run-Time (semantic) errors Logic errors Project Debugging

Homework • Text Box Walkthrough: p. 43

• Command Button Walkthrough: p. 49
• Label Walkthrough: p. 50 • Picture Box Walkthrough: p. 51