Illuminating Computer Science CCIT 4-6Sep

91
Illuminating Computer Science CCIT 4-6Sep http://www.aast.edu/en/colleges/ccit/cs4hs/

Transcript of Illuminating Computer Science CCIT 4-6Sep

Page 1: Illuminating Computer Science CCIT 4-6Sep

Illuminating Computer Science CCIT 4-6Sep http://www.aast.edu/en/colleges/ccit/cs4hs/

Page 2: Illuminating Computer Science CCIT 4-6Sep

Introduction to Introduction to Programming ConceptsProgramming Concepts

Visual Basic: an Introduction

Illuminating Computer Science CCIT 4-6Sep http://www.aast.edu/en/colleges/ccit/cs4hs/

Page 3: Illuminating Computer Science CCIT 4-6Sep

Illuminating Computer Science CCIT 4-6Sep http://www.aast.edu/en/colleges/ccit/cs4hs/

ObjectivesObjectives

The audience should be familiar with the Visual Basic Environment.

The audience should be able to build simple Visual Basic Applications.

The audience should learn the precedence rules for writing equations.

The audience should be able to write programs using control structures

Page 4: Illuminating Computer Science CCIT 4-6Sep

Illuminating Computer Science CCIT 4-6Sep http://www.aast.edu/en/colleges/ccit/cs4hs/

Performing a Task on the Performing a Task on the ComputerComputerDetermine OutputIdentify InputDetermine process necessary to turn

given Input into desired Output

Page 5: Illuminating Computer Science CCIT 4-6Sep

Illuminating Computer Science CCIT 4-6Sep http://www.aast.edu/en/colleges/ccit/cs4hs/

Problem-solving approach like Problem-solving approach like algebra classalgebra classHow fast is a car traveling if it goes

50 miles in 2 hours?Output: a number giving the rate of

speed in Km per hourInput: the distance and time the car

has traveledProcess: rate = distance/time

Page 6: Illuminating Computer Science CCIT 4-6Sep

Illuminating Computer Science CCIT 4-6Sep http://www.aast.edu/en/colleges/ccit/cs4hs/

Pictorial representation of the Pictorial representation of the problem solving processproblem solving process

Page 7: Illuminating Computer Science CCIT 4-6Sep

Illuminating Computer Science CCIT 4-6Sep http://www.aast.edu/en/colleges/ccit/cs4hs/

Program Planning TipsProgram Planning Tips

Always have a plan before trying to write a program

The more complicated the problem, the more complex the plan must be

Planning and testing before coding saves time coding

Page 8: Illuminating Computer Science CCIT 4-6Sep

Illuminating Computer Science CCIT 4-6Sep http://www.aast.edu/en/colleges/ccit/cs4hs/

Simplified Program development Simplified Program development cyclecycle

1. Analyze: Define the problem.

2. Design: Plan the solution to the problem.

3. Choose the interface: Select the objects (text boxes, buttons, etc.).

Page 9: Illuminating Computer Science CCIT 4-6Sep

Illuminating Computer Science CCIT 4-6Sep http://www.aast.edu/en/colleges/ccit/cs4hs/

Program development cycle Program development cycle continuedcontinued4. Code: Translate the algorithm into a

programming language.Try to avoid jumping straight to this step, which can result in a sloppy solution!

5. Test and debug: Locate and remove any errors in the program.

6. Complete the documentation: Organize all the material that describes the program.

Page 10: Illuminating Computer Science CCIT 4-6Sep

Illuminating Computer Science CCIT 4-6Sep http://www.aast.edu/en/colleges/ccit/cs4hs/

What is Visual Basic?What is Visual Basic?

High Level 4th Generation Programming Language

Object and Event DrivenVisual - Windows Based Integrated Development Environment

or IDE

Page 11: Illuminating Computer Science CCIT 4-6Sep

Illuminating Computer Science CCIT 4-6Sep http://www.aast.edu/en/colleges/ccit/cs4hs/

What is VB Used For?What is VB Used For?Most Popular Programming LanguageStand alone programsApplets that can be run on many

different kinds of computersCustomized specialized Applications

– E- Commerce • Web based shopping forms and inquiries

User friendly Interface to applications

Page 12: Illuminating Computer Science CCIT 4-6Sep

Illuminating Computer Science CCIT 4-6Sep http://www.aast.edu/en/colleges/ccit/cs4hs/

Used by a computer equipment retail outlet to record data regarding customer orders.

Example Order Entry Example Order Entry ScreenScreen

Allows user to use a mouse to click on boxes for text entry.

Also enables user to click on buttons to initiate processing steps.

Page 13: Illuminating Computer Science CCIT 4-6Sep

Illuminating Computer Science CCIT 4-6Sep http://www.aast.edu/en/colleges/ccit/cs4hs/

Generations of Computer LanguagesGenerations of Computer Languages

1st - Machine language - 0110 0011 1000

2nd - Procedure-oriented languages – FORTRAN - 1954 for scientists and engineers

– COBOL - 1959 for business applications

– C - 1972 - for UNIX operating systems

3rd - Object-oriented languages4th - Event-driven languages - i.e.VB5th - Natural languages i.e. English

Page 14: Illuminating Computer Science CCIT 4-6Sep

Illuminating Computer Science CCIT 4-6Sep http://www.aast.edu/en/colleges/ccit/cs4hs/

Compiler Vs InterpreterCompiler Vs Interpreter

Higher Languages are translated to Machine Language by:– Interpreter

• Translates instructions to machine code line-by-line.

• BASIC, Quick Basic, Visual Basic

– Compiler • Translates the entire program to machine

code before running it.• Fortran, C, C++, Visual Basic is also a compiler

Page 15: Illuminating Computer Science CCIT 4-6Sep

Illuminating Computer Science CCIT 4-6Sep http://www.aast.edu/en/colleges/ccit/cs4hs/

What are the Objects in VB?What are the Objects in VB?

Pre-programmed Code for:– Command Buttons– Labels– Pictures– Text Boxes

Have both data and procedures wrapped together

Page 16: Illuminating Computer Science CCIT 4-6Sep

Illuminating Computer Science CCIT 4-6Sep http://www.aast.edu/en/colleges/ccit/cs4hs/

What are the Events?What are the Events?

– Visual Basic “watches” what the user does

– A user activity is called an event– Events include mouse clicks and

moves, menu selections, button presses, etc.

– Sections of code are only executed in response to an event

Page 17: Illuminating Computer Science CCIT 4-6Sep

Illuminating Computer Science CCIT 4-6Sep http://www.aast.edu/en/colleges/ccit/cs4hs/

What is the Integrated Development What is the Integrated Development Environment (IDE)?Environment (IDE)?

Page 18: Illuminating Computer Science CCIT 4-6Sep

Illuminating Computer Science CCIT 4-6Sep http://www.aast.edu/en/colleges/ccit/cs4hs/

Visual Basic EnvironmentVisual Basic Environment

GUI (Graphical User Interface) - forms and windows that the user sees

Property - a characteristic or attribute of an object such as color and size

Event - a user action such as clicking a button

Code Editor window - editor specially designed to help you when writing code

Page 19: Illuminating Computer Science CCIT 4-6Sep

Illuminating Computer Science CCIT 4-6Sep http://www.aast.edu/en/colleges/ccit/cs4hs/

Visual Basic EnvironmentVisual Basic EnvironmentComponents of the VB design

environment (Form view)

Page 20: Illuminating Computer Science CCIT 4-6Sep

Illuminating Computer Science CCIT 4-6Sep http://www.aast.edu/en/colleges/ccit/cs4hs/

Visual Basic EnvironmentVisual Basic EnvironmentComponents of the VB design

environment (Code view)

Page 21: Illuminating Computer Science CCIT 4-6Sep

Illuminating Computer Science CCIT 4-6Sep http://www.aast.edu/en/colleges/ccit/cs4hs/

The Code Editor WindowThe Code Editor WindowObject List Box

Procedure List Box

Auto List Members

Full Module View button

Page 22: Illuminating Computer Science CCIT 4-6Sep

Illuminating Computer Science CCIT 4-6Sep http://www.aast.edu/en/colleges/ccit/cs4hs/

The Code Editor WindowThe Code Editor Window

Help window

Error message box

Syntax error in Red

Procedure view button

Page 23: Illuminating Computer Science CCIT 4-6Sep

Illuminating Computer Science CCIT 4-6Sep http://www.aast.edu/en/colleges/ccit/cs4hs/

VB Environment: Project VB Environment: Project WindowWindow

The Project Window can be used to navigate between the code and form window for each form / window a project has

Page 24: Illuminating Computer Science CCIT 4-6Sep

Illuminating Computer Science CCIT 4-6Sep http://www.aast.edu/en/colleges/ccit/cs4hs/

VB Environment: Menu BarVB Environment: Menu Bar

The Menu Bar consists of 3 elements the–Title Bar, which holds the name of application,

default if Microsoft Visual Basic [design]–Menu Bar, this is the link to Visual Basics menu

facilities, each menu option drops down into sub-menus

–Toolbar, contains icons which give access to the more commonly used commands (which are also available through the menu bar)

Title bar Menu Bar Toolbar

Page 25: Illuminating Computer Science CCIT 4-6Sep

Illuminating Computer Science CCIT 4-6Sep http://www.aast.edu/en/colleges/ccit/cs4hs/

VB Environment: Properties VB Environment: Properties WindowWindowUsed to set how a

control looks andbehaves

Holds its default values

Page 26: Illuminating Computer Science CCIT 4-6Sep

Illuminating Computer Science CCIT 4-6Sep http://www.aast.edu/en/colleges/ccit/cs4hs/

VB Environment: Control VB Environment: Control ToolboxToolbox

Pointer

Label

Group Frame

Check Box

Combo Box

Horizontal Scroll Bar

Timer

Directory List Box

Shape

Image

OLE

Picture

Text Box

Command Button

Option/Radio Button

List Box

Vertical Scroll Bar

Drive List Box

File List Box

Line

Data Control

Page 27: Illuminating Computer Science CCIT 4-6Sep

Illuminating Computer Science CCIT 4-6Sep http://www.aast.edu/en/colleges/ccit/cs4hs/

VB Environment: Context VB Environment: Context Sensitive Help Sensitive Help Context sensitive help is very usefulSelect the item control that you want help onPress the F1 key

F1

Page 28: Illuminating Computer Science CCIT 4-6Sep

Illuminating Computer Science CCIT 4-6Sep http://www.aast.edu/en/colleges/ccit/cs4hs/

The File MenuThe File Menu

Project commands

Make executable commands

Most recent project list

Exit command

Page 29: Illuminating Computer Science CCIT 4-6Sep

Illuminating Computer Science CCIT 4-6Sep http://www.aast.edu/en/colleges/ccit/cs4hs/

The File MenuThe File Menu

New Project Open Project Add Project Remove Project Save Project Save Project As

Save Component Save Component

As Print Print Setup

Page 30: Illuminating Computer Science CCIT 4-6Sep

Illuminating Computer Science CCIT 4-6Sep http://www.aast.edu/en/colleges/ccit/cs4hs/

The File MenuThe File Menu

Template - particular pattern for a project or a project element; start a project from a template saves time

Existing tab - displays VB projects

Recent tab - displays most recently accessed projects

Project Groups - a collection of several projects

Page 31: Illuminating Computer Science CCIT 4-6Sep

Illuminating Computer Science CCIT 4-6Sep http://www.aast.edu/en/colleges/ccit/cs4hs/

Building Your First ApplicationBuilding Your First Application

There are three primary steps in building a Visual Project:– Place (or draw) controls on the form.– Assign properties to the controls.– Write event procedures for the controls.

Page 32: Illuminating Computer Science CCIT 4-6Sep

Illuminating Computer Science CCIT 4-6Sep http://www.aast.edu/en/colleges/ccit/cs4hs/

Project FilesProject Files

vbp extension = Visual Basic Project– file that tracks all components

frm extension = Form file– separate file for each form

frx extension = Binary form file– cannot be read by humans

vbw extension = Visual Basic workspace

Page 33: Illuminating Computer Science CCIT 4-6Sep

Illuminating Computer Science CCIT 4-6Sep http://www.aast.edu/en/colleges/ccit/cs4hs/

Starting Visual BasicStarting Visual Basic

Page 34: Illuminating Computer Science CCIT 4-6Sep

Illuminating Computer Science CCIT 4-6Sep http://www.aast.edu/en/colleges/ccit/cs4hs/

Choosing Project TypeChoosing Project Type

Page 35: Illuminating Computer Science CCIT 4-6Sep

Illuminating Computer Science CCIT 4-6Sep http://www.aast.edu/en/colleges/ccit/cs4hs/

Placing Controls on the Form: ImagePlacing Controls on the Form: Image

Page 36: Illuminating Computer Science CCIT 4-6Sep

Illuminating Computer Science CCIT 4-6Sep http://www.aast.edu/en/colleges/ccit/cs4hs/

Assigning Properties to ControlsAssigning Properties to Controls

Page 37: Illuminating Computer Science CCIT 4-6Sep

Illuminating Computer Science CCIT 4-6Sep http://www.aast.edu/en/colleges/ccit/cs4hs/

Adding an ImageAdding an Image

Page 38: Illuminating Computer Science CCIT 4-6Sep

Illuminating Computer Science CCIT 4-6Sep http://www.aast.edu/en/colleges/ccit/cs4hs/

Browse for an ImageBrowse for an Image

Page 39: Illuminating Computer Science CCIT 4-6Sep

Illuminating Computer Science CCIT 4-6Sep http://www.aast.edu/en/colleges/ccit/cs4hs/

Image DisplayedImage Displayed

Page 40: Illuminating Computer Science CCIT 4-6Sep

Illuminating Computer Science CCIT 4-6Sep http://www.aast.edu/en/colleges/ccit/cs4hs/

Buttons and Text BoxesButtons and Text Boxes

Page 41: Illuminating Computer Science CCIT 4-6Sep

Illuminating Computer Science CCIT 4-6Sep http://www.aast.edu/en/colleges/ccit/cs4hs/

Changing the Form TitleChanging the Form Title

Page 42: Illuminating Computer Science CCIT 4-6Sep

Illuminating Computer Science CCIT 4-6Sep http://www.aast.edu/en/colleges/ccit/cs4hs/

Writing the Code (Events)Writing the Code (Events)

Page 43: Illuminating Computer Science CCIT 4-6Sep

Illuminating Computer Science CCIT 4-6Sep http://www.aast.edu/en/colleges/ccit/cs4hs/

Writing the Code (Events)Writing the Code (Events)

Page 44: Illuminating Computer Science CCIT 4-6Sep

Illuminating Computer Science CCIT 4-6Sep http://www.aast.edu/en/colleges/ccit/cs4hs/

Running the ApplicationRunning the Application

Page 45: Illuminating Computer Science CCIT 4-6Sep

Illuminating Computer Science CCIT 4-6Sep http://www.aast.edu/en/colleges/ccit/cs4hs/

Running the ApplicationRunning the Application

Page 46: Illuminating Computer Science CCIT 4-6Sep

Illuminating Computer Science CCIT 4-6Sep http://www.aast.edu/en/colleges/ccit/cs4hs/

More Complex StructuresMore Complex Structures

Page 47: Illuminating Computer Science CCIT 4-6Sep

Illuminating Computer Science CCIT 4-6Sep http://www.aast.edu/en/colleges/ccit/cs4hs/

Syntax BoxesSyntax Boxes

Syntax for a Visual Basic statement is shown in a syntax box

Reserved words are shown in boldProgrammer named words are shown in

italics

Page 48: Illuminating Computer Science CCIT 4-6Sep

Illuminating Computer Science CCIT 4-6Sep http://www.aast.edu/en/colleges/ccit/cs4hs/

The Sub StatementThe Sub Statement

Private Sub controlname_eventname( )

Statements

End SubWhere

Private is the default procedure type

Sub indicates beginning of procedure

controlname is name of associated control

_ (underscore) required separator

eventname is name of corresponding event

( ) set of parentheses is required

End Sub indicates end of a procedure

Page 49: Illuminating Computer Science CCIT 4-6Sep

Illuminating Computer Science CCIT 4-6Sep http://www.aast.edu/en/colleges/ccit/cs4hs/

The Sub StatementThe Sub Statement

Example

Private Sub cmdCalcTriangle_Click

Dim Base As Single

Dim Height As Single

Dim Height As Single

Area = 1 / 2 * (Base * Height)

End Sub

Page 50: Illuminating Computer Science CCIT 4-6Sep

Illuminating Computer Science CCIT 4-6Sep http://www.aast.edu/en/colleges/ccit/cs4hs/

Declarations, Variables, Declarations, Variables, and Constantsand Constants

Variable - a uniquely named storage location that contains data that changes during program execution

Constant - a uniquely named storage locations that contains data that does not change during program execution

Page 51: Illuminating Computer Science CCIT 4-6Sep

Illuminating Computer Science CCIT 4-6Sep http://www.aast.edu/en/colleges/ccit/cs4hs/

Declarations, Variables,Declarations, Variables,and Constantsand Constants

Rules for Naming Variables– Must begin with an alphabetic character– Can’t contain a period or type-declaration

characters such as %, &, !, #, @ or $

– Must be unique with same scope– Must be no longer than 255 characters– Should not reserved word (See Appendix A)

Page 52: Illuminating Computer Science CCIT 4-6Sep

Illuminating Computer Science CCIT 4-6Sep http://www.aast.edu/en/colleges/ccit/cs4hs/

Declaring VariablesDeclaring Variables

Declaration statement - nonexecutable code that sets aside storage locations for future use

Local variables - declared within a procedure or function

Global variables - declared in the general section of the application

Page 53: Illuminating Computer Science CCIT 4-6Sep

Illuminating Computer Science CCIT 4-6Sep http://www.aast.edu/en/colleges/ccit/cs4hs/

Declaring VariablesDeclaring Variables

Declare variables using the Dim or Static statementsDim statement - value of variable

preserved only until procedure ends

Static statement - value of variable preserved the entire time the application is running

Page 54: Illuminating Computer Science CCIT 4-6Sep

Illuminating Computer Science CCIT 4-6Sep http://www.aast.edu/en/colleges/ccit/cs4hs/

The Dim StatementThe Dim Statement

Dim variablename As datatype

Where

Dim is required

variablename should be a descriptive name

As is required

datatype is one of the following types:

Boolean, Byte, Date, Integer, Long, Single,

Double, Currency, String, Object or Variant

Page 55: Illuminating Computer Science CCIT 4-6Sep

Illuminating Computer Science CCIT 4-6Sep http://www.aast.edu/en/colleges/ccit/cs4hs/

Declaring VariablesDeclaring Variables

Data Types– Boolean - True or false– Date - From Jan 1, 100 to Dec 31, 9999– Integer - Numbers without a decimal point– Long - Long integer– Single - Numbers with a decimal point– Double - Long Single– Currency - Dollar amounts– String - Character and alphanumeric data– Object - Any object reference such as Word document– Variant - default, can hold any data type

Page 56: Illuminating Computer Science CCIT 4-6Sep

Illuminating Computer Science CCIT 4-6Sep http://www.aast.edu/en/colleges/ccit/cs4hs/

Assigning Values to VariablesAssigning Values to Variables

Variablename = value

Where

variablename is the descriptive name of the variable

= is the assignment operator

value is the value the variable will contain

Examples:Number1 = 5FirstName = “Steve”LoanAmount = 67.38Length = 17.8

Note: Order is important. Variable name always on the left, and value on the right.

Page 57: Illuminating Computer Science CCIT 4-6Sep

Illuminating Computer Science CCIT 4-6Sep http://www.aast.edu/en/colleges/ccit/cs4hs/

Declaring Constants Declaring Constants

Const constantname As datatype = value

Where

Const is required

constantname is the descriptive name of the constant

As is required

datatype is the type of data the constant will contain

= is the assignment operator

value is the value of the constant

Examples:Const Pi As Single 3.14159265358979Const MaxNumber As Integer = 100

Page 58: Illuminating Computer Science CCIT 4-6Sep

Illuminating Computer Science CCIT 4-6Sep http://www.aast.edu/en/colleges/ccit/cs4hs/

FunctionsFunctions

Function - unit of code that returns a value

Built-in Functions– Sqr - square root– Rnd - random number generator– Int - returns integer portion of a number– Val - converts a string to a value– Str - converts a value to a string

Page 59: Illuminating Computer Science CCIT 4-6Sep

Illuminating Computer Science CCIT 4-6Sep http://www.aast.edu/en/colleges/ccit/cs4hs/

Application 1: Calculate the area of Application 1: Calculate the area of a circlea circle Inputs: radius of the circle r Output: area of the circle Process: Area=

2r

Page 60: Illuminating Computer Science CCIT 4-6Sep

Illuminating Computer Science CCIT 4-6Sep http://www.aast.edu/en/colleges/ccit/cs4hs/

Application 1: Calculate the area of Application 1: Calculate the area of a circle (Form View)a circle (Form View)

Page 61: Illuminating Computer Science CCIT 4-6Sep

Illuminating Computer Science CCIT 4-6Sep http://www.aast.edu/en/colleges/ccit/cs4hs/

Application 1: Calculate the area of Application 1: Calculate the area of a circle (Code View)a circle (Code View)

Page 62: Illuminating Computer Science CCIT 4-6Sep

Illuminating Computer Science CCIT 4-6Sep http://www.aast.edu/en/colleges/ccit/cs4hs/

Application 1: Calculate the area of Application 1: Calculate the area of a circle (Run)a circle (Run)

Page 63: Illuminating Computer Science CCIT 4-6Sep

Illuminating Computer Science CCIT 4-6Sep http://www.aast.edu/en/colleges/ccit/cs4hs/

Precedence TablePrecedence Table

Operator

( )

^

*, /

+,-

If precedence of two following operators is equal, then the evaluation starts from left to right.

Page 64: Illuminating Computer Science CCIT 4-6Sep

Illuminating Computer Science CCIT 4-6Sep http://www.aast.edu/en/colleges/ccit/cs4hs/

Simple Examples of EquationsSimple Examples of Equations

Equation in normal form:– Y=3X– Y=X-10+3(X-Z)– Y=X^2*10– Y= X

Equation in VB form:– Y=3*X– Y=X-10+3*(X-Z)– Y=X*X*10– Y=SQR(X)

Page 65: Illuminating Computer Science CCIT 4-6Sep

Illuminating Computer Science CCIT 4-6Sep http://www.aast.edu/en/colleges/ccit/cs4hs/

Application 2: Convert from Application 2: Convert from Fahrenheit Degree to Celsius Fahrenheit Degree to Celsius Original formula:

Celsius=5/9(Fahrenheit-32)Visual Basic formula:

Celsius=5/9*(Fahrenheit-32)Input: FahrenheitOutput: CelsiusProcess: Celsius=5/9*(Fahrenheit-32)

Page 66: Illuminating Computer Science CCIT 4-6Sep

Illuminating Computer Science CCIT 4-6Sep http://www.aast.edu/en/colleges/ccit/cs4hs/

Application 2: Convert from Application 2: Convert from Fahrenheit Degree to Celsius (Form Fahrenheit Degree to Celsius (Form View)View)

Page 67: Illuminating Computer Science CCIT 4-6Sep

Illuminating Computer Science CCIT 4-6Sep http://www.aast.edu/en/colleges/ccit/cs4hs/

Application 2: Convert from Application 2: Convert from Fahrenheit Degree to Celsius (Code Fahrenheit Degree to Celsius (Code View)View)

Page 68: Illuminating Computer Science CCIT 4-6Sep

Illuminating Computer Science CCIT 4-6Sep http://www.aast.edu/en/colleges/ccit/cs4hs/

Application 2: Convert from Application 2: Convert from Fahrenheit Degree to Celsius (Run)Fahrenheit Degree to Celsius (Run)

Page 69: Illuminating Computer Science CCIT 4-6Sep

Illuminating Computer Science CCIT 4-6Sep http://www.aast.edu/en/colleges/ccit/cs4hs/

Application 3: The Wind Chill Application 3: The Wind Chill ApplicationApplicationWrite a program that calculates

the wind chill temperatureInputs: Wind Speed and TemperatureOutputs: Wind Chill Temperature

Page 70: Illuminating Computer Science CCIT 4-6Sep

Illuminating Computer Science CCIT 4-6Sep http://www.aast.edu/en/colleges/ccit/cs4hs/

Application 3:The Wind Chill Application 3:The Wind Chill ApplicationApplication Original formula

– WC = 0.0817(3.71(V **0.5) + 5.81 - 0.25V)(T - 91.4) + 91.4

Visual Basic statement– WC = 0.0817 * (3.71 * Sqr(V) + 5.81 -(0.25 * V)) *

(T - 91.4) + 91.4 Output: Wind Chill (WC) Input 1 T: Temperature Input 2 V: Wind Speed

Page 71: Illuminating Computer Science CCIT 4-6Sep

Illuminating Computer Science CCIT 4-6Sep http://www.aast.edu/en/colleges/ccit/cs4hs/

Adding Controls and Changing their Adding Controls and Changing their PropertiesProperties

Page 72: Illuminating Computer Science CCIT 4-6Sep

Illuminating Computer Science CCIT 4-6Sep http://www.aast.edu/en/colleges/ccit/cs4hs/

Writing the CodeWriting the Code

Page 73: Illuminating Computer Science CCIT 4-6Sep

Illuminating Computer Science CCIT 4-6Sep http://www.aast.edu/en/colleges/ccit/cs4hs/

Running the ApplicationRunning the Application

Page 74: Illuminating Computer Science CCIT 4-6Sep

Illuminating Computer Science CCIT 4-6Sep http://www.aast.edu/en/colleges/ccit/cs4hs/

Control StructuresControl Structures

Page 75: Illuminating Computer Science CCIT 4-6Sep

Illuminating Computer Science CCIT 4-6Sep http://www.aast.edu/en/colleges/ccit/cs4hs/

Controlling your ApplicationControlling your Application

Sequence

Selection– If...Then...Else statement– Select Case statement

Repetition– For...Next Loop statement– For Each...Next statement– Do Loops

Page 76: Illuminating Computer Science CCIT 4-6Sep

Illuminating Computer Science CCIT 4-6Sep http://www.aast.edu/en/colleges/ccit/cs4hs/

Selection If..Then..ElseSelection If..Then..Else

If (condition) Then (statement[s])

[ElseIf (condition) Then (statement[s])]

[Else (statement[s])]

Page 77: Illuminating Computer Science CCIT 4-6Sep

Illuminating Computer Science CCIT 4-6Sep http://www.aast.edu/en/colleges/ccit/cs4hs/

Selection Application: Convert from Selection Application: Convert from Numerical Grade to Letter GradeNumerical Grade to Letter Grade Input: a numeric grade between 0 and

100 Output: depends on input

Input Output

049 F

5052 D

5356 D+

5760 C-

6164 C

6569 C+

7074 B-

7579 B

8084 B+

8589 A-

90100 A

Page 78: Illuminating Computer Science CCIT 4-6Sep

Illuminating Computer Science CCIT 4-6Sep http://www.aast.edu/en/colleges/ccit/cs4hs/

Selection Application: Convert from Selection Application: Convert from Numerical Grade to Letter Grade (Form Numerical Grade to Letter Grade (Form View)View)

Page 79: Illuminating Computer Science CCIT 4-6Sep

Illuminating Computer Science CCIT 4-6Sep http://www.aast.edu/en/colleges/ccit/cs4hs/

Selection Application: Convert from Selection Application: Convert from Numerical Grade to Letter Grade (Code Numerical Grade to Letter Grade (Code View)View)

Page 80: Illuminating Computer Science CCIT 4-6Sep

Illuminating Computer Science CCIT 4-6Sep http://www.aast.edu/en/colleges/ccit/cs4hs/

Selection Application: Convert from Selection Application: Convert from Numerical Grade to Letter Grade Numerical Grade to Letter Grade (Run)(Run)

Page 81: Illuminating Computer Science CCIT 4-6Sep

Illuminating Computer Science CCIT 4-6Sep http://www.aast.edu/en/colleges/ccit/cs4hs/

For...Next Loop StructureFor...Next Loop StructureFor counter = start To end Step increment

statements

Next counter

Where

Counter is tested to see if less than end.If so, repeat loop again. If not, go to

statement after Next.

Page 82: Illuminating Computer Science CCIT 4-6Sep

Illuminating Computer Science CCIT 4-6Sep http://www.aast.edu/en/colleges/ccit/cs4hs/

Do While...Loop StructureDo While...Loop StructureDo While condition

statements

Loop

Where

The condition is tested, and if true the loop isrepeated. When the condition is false, the loopstatements are skipped the statement after

Loopis executed.

Page 83: Illuminating Computer Science CCIT 4-6Sep

Illuminating Computer Science CCIT 4-6Sep http://www.aast.edu/en/colleges/ccit/cs4hs/

Do Until...Loop StructureDo Until...Loop StructureDo Until condition

statements

Loop

Where

The condition is tested, and if false the loop isrepeated. When the condition is true, the loopstatements are skipped the statement after

Loopis executed.

Page 84: Illuminating Computer Science CCIT 4-6Sep

Illuminating Computer Science CCIT 4-6Sep http://www.aast.edu/en/colleges/ccit/cs4hs/

Loops Application: FactorialLoops Application: Factorial

Factorial (N)= N*(N-1)*(N-2)……….*(1)

Page 85: Illuminating Computer Science CCIT 4-6Sep

Illuminating Computer Science CCIT 4-6Sep http://www.aast.edu/en/colleges/ccit/cs4hs/

Factorial Flowchart (N>0)Factorial Flowchart (N>0)

Page 86: Illuminating Computer Science CCIT 4-6Sep

Illuminating Computer Science CCIT 4-6Sep http://www.aast.edu/en/colleges/ccit/cs4hs/

Factorial Application: Form ViewFactorial Application: Form View

Page 87: Illuminating Computer Science CCIT 4-6Sep

Illuminating Computer Science CCIT 4-6Sep http://www.aast.edu/en/colleges/ccit/cs4hs/

Factorial Application: Code ViewFactorial Application: Code ViewUsing For..Next LoopUsing For..Next Loop

Page 88: Illuminating Computer Science CCIT 4-6Sep

Illuminating Computer Science CCIT 4-6Sep http://www.aast.edu/en/colleges/ccit/cs4hs/

Factorial Application: Code ViewFactorial Application: Code ViewUsing Do..While..LoopUsing Do..While..Loop

Page 89: Illuminating Computer Science CCIT 4-6Sep

Illuminating Computer Science CCIT 4-6Sep http://www.aast.edu/en/colleges/ccit/cs4hs/

Factorial Application: Code ViewFactorial Application: Code ViewUsing Do..Until..LoopUsing Do..Until..Loop

Page 90: Illuminating Computer Science CCIT 4-6Sep

Illuminating Computer Science CCIT 4-6Sep http://www.aast.edu/en/colleges/ccit/cs4hs/

Factorial Application: RunFactorial Application: Run

Page 91: Illuminating Computer Science CCIT 4-6Sep

Illuminating Computer Science CCIT 4-6Sep http://www.aast.edu/en/colleges/ccit/cs4hs/

SummarySummary

After the completion of this lecture, the audience should be familiar with the visual basic environment and different controls.

The audience should be able to write simple programs and generate simple VB applications.