Visual BASIC - PowerPoint PPT Presentation

1 / 52
About This Presentation
Title:

Visual BASIC

Description:

(1) Parenthesis, Functions, Exponentiation (2) Multiplication, Division ... Parenthesis. Parenthesis are used to alter the order with which operations are evaluated ... – PowerPoint PPT presentation

Number of Views:29
Avg rating:3.0/5.0
Slides: 53
Provided by: joe9
Category:
Tags: basic | action | big | man | on | parenthesis | tube | visual

less

Transcript and Presenter's Notes

Title: Visual BASIC


1
Visual BASIC
  • Fundamentals

2
Algorithms
  • An algorithm is a method for solving a problem
  • A sequence of precise instructions that leads to
    a solution
  • It is a model of the solution
  • It should be
  • unambiguous
  • executable
  • terminating

3
Problem Solving
  • Know
  • Need
  • Do

4
Know
  • What do I know?
  • What facts am I starting with?
  • Define the problem

5
Need
  • What do I need?
  • Whats missing?
  • What other facts do I need to find or determine?

6
Do
  • What do I need to do?
  • Develop a method, a solution, an algorithm for
    solving the problem
  • Execute the algorithm

7
In the Beginning ...
  • The first devices to be used were vacumn tubes
  • They had two states
  • They were hot and required lots of air
    conditioning
  • They were fairly big and needed lots of wiring
  • They burnt out often

8
Getting Smaller ...
  • Next came transisters
  • They had two states
  • They produced far less heat
  • They were smaller and therefore needed less
    wiring
  • Less wiring meant shorter distances for electrons
    to travel and thus faster computers

9
Smaller Yet ...
  • Today, we use integrated circuits, which combine
    transisters and other components into
    photographically microtized circuits
  • They are essentially cool
  • They need very little wiring and therefore are
    even faster

10
Try this!
  • Problem
  • If you had a panel with three light switches, how
    many unique combinations of up and down could you
    create?
  • Break into groups of 4
  • Work on the problem for 10 minutes
  • Go!

11
Try this!
  • Answer
  • Each switch has two possible states(up or down
    )
  • 2 ? 2 ? 2 8 possible combinations
  • How many combinations for 4 switches?
  • 6 switches?
  • 8 switches?

12
Binary Numbers
  • Use two digits, 0 and 1
  • Decimal numbers use digits 0 through 9
  • The decimal number 23 would be the binary number
    10111
  • Bit a binary digit
  • Byte an eight digit binary number
  • Each bit requires a device with two possible
    states

13
Try this!
  • What decimal number is each of the following
    binary numbers equal to?
  • 1010
  • 1001
  • 1100
  • 111010
  • 11111111

14
A Basic Computer
15
A Basic Computer
CPU
Central Processing Unit - where data is processed
16
A Basic Computer
CPU
ROM
Read Only Memory - Manufacturer supplied data and
instructions
17
A Basic Computer
CPU
ROM
RAM
Random Access Memory - User supplied data and
instructions
18
A Basic Computer
CPU
InputDevice
ROM
RAM
Allows user to supply data to CPU directly
19
A Basic Computer
CPU
InputDevice
OutputDevice
ROM
RAM
Allows CPU to send data to user directly
20
A Basic Computer
CPU
InputDevice
OutputDevice
ROM
RAM
SecondaryStorage
Semi-permanent storage - device and medium
21
Bits Bytes
  • Computer instructions are stored using numerical
    codes
  • Each family of CPUs has its own instruction set
  • An instruction set is a collection of instruction
    codes
  • This is why an Intel CPU based program wont
    necessarily run on a Power PC CPU

22
Programming Languages
  • Machine language
  • Assembly language
  • Higher level languages
  • Interpreted languagesBASIC, APL
  • Compiled languagesC, Pascal, Fortran, Cobol

23
Machine Language
  • The language of the computer (CPU)
  • Essentially, the instruction set

24
Assembly Language
  • Very similar to machine language
  • Instruction codes are replaced with short
    abbreviations
  • Requires an assembler (program) to translate into
    machine language

25
Higher Level Interpreted
  • Instructions similar to written sentences and/or
    arithmetic expressions
  • Requires an interpreter (program) to translate
    into machine language
  • Each instruction is executed immediately after it
    is translated

26
Higher Level Compiled
  • Instructions similar to written sentences and/or
    arithmetic expressions
  • Requires a compiler (program) to translate into
    machine language
  • Instructions are first translated, and then the
    entire translated program is executed

27
Programming Paradigms
  • Procedural
  • Functional
  • Declarative
  • Object-oriented

28
Procedural Programming
  • Methods (algorithms) are developed to solve
    problem
  • Step-by-step solutions
  • BASIC, FORTRAN, COBOL, Pascal, C

29
Functional Programming
  • Discrete components called functions that map
    arguments to outputs
  • APL, C, Lisp

30
Declarative Programming
  • Facts and rules
  • PROLOG

31
Object-Oriented Programming
  • Data structures, instead of instructions, are
    defined as classes of objects
  • Each class has its own description
  • This includes attributes (data members) and
    methods (member functions)
  • C, Eifel, Ada, Visual Basic

32
Object-Oriented Programming
  • Objects
  • a thing, or noun
  • described by what they look like and what they do
  • Properties
  • attributes, or adjectives
  • what an object looks like
  • For example, color, size, length, etc.
  • Methods
  • actions, or verbs
  • what objects can do

33
What is Visual Basic
  • A programming language
  • Object-oriented
  • Event-driven

34
Event-Driven Programming
  • User actions produces messages
  • Messages are passed to objects
  • Objects respond via methods

35
Assignment
  • When a variable is declared, space is allocated
    in the computers memory for the variable
  • Each data type requires a different number of
    bytes in memory
  • Integer - 2Single - 4Double - 8Boolean -
    1String - 1 per character

36
Assignment
  • When a variable is assigned a value, the value is
    placed into the variables memory location

Total 2 3 5
Total
10
37
Arithmetic Operations
  • Addition 2 3
  • Subtraction 5 - 2
  • Multiplication 10 4
  • Division 12 / 3
  • Exponentiation 32

38
Order of Operations
  • Arithmetic expressions are evaluated according to
    the following order of operations
  • At each level, operations are evaluated left to
    right
  • (1) Parenthesis, Functions, Exponentiation(2)
    Multiplication, Division(3) Addition, Subtraction

39
Parenthesis
  • Parenthesis are used to alter the order with
    which operations are evaluated
  • Ex.
  • 4 5 2 equals 14
  • (4 5) 2 equals 18

40
VB Projects
  • Project File
  • filename.VBP
  • description of the project
  • Forms (form modules)
  • filename.FRM
  • description of objects, and their properties and
    methods
  • Standard Code Modules
  • filename.BAS
  • additional BASIC statements

41
VB Objects
  • Label
  • Static text
  • lbl
  • Text box
  • Dynamic text
  • txt
  • Command button
  • Initiates user-selected action
  • cmd
  • List box
  • Text list
  • lst
  • Menus
  • Nuf said!
  • men
  • Radio button, Check box
  • Selection
  • and more ...

42
Adding an Object
  • Click on icon in object menu
  • Position crosshairs for first corner
  • Hold down left mouse button

43
Adding an Object
  • Click on icon in object menu
  • Position crosshairs for first corner
  • Hold down left mouse button
  • Drag crosshairs to opposite object corner
  • Release button
  • Edit object properties

44
Adding a Method
  • Double-click on object in frame
  • Editing window will appear
  • Each method is a subroutine
  • Whats a subroutine?
  • Well deal with that later
  • Add instructions to method
  • Execute program to test

Label
Caption
Command
45
Try This!
  • Develop a method for determining the net pay for
    an employee based upon the employees gross pay,
    federal income tax rate and union dues
  • Your method should include names (identifiers)
    for all known and unknown values

46
Know?
  • Gross pay
  • Tax rate
  • Union dues

47
Need?
  • Tax
  • Net Pay
  • How to calculate the above

48
Do?
  • Create an algorithm
  • Tax is tax rate times gross payTax Tax Rate ?
    Gross Pay
  • Net pay is gross pay less all deductionsNet Pay
    Gross Pay - (Tax Union Dues)
  • Implement algorithm as program
  • Execute program
  • (Debug, debug, debug!!!)

49
Implement as Program
  • Design an interface
  • txtGrossPay
  • txtTaxRate
  • txtUnionDues
  • lblTax
  • lblNetPay
  • cmdCalc
  • cmdClear
  • cmdExit

Gross Pay
Tax Rate
Union Dues
Tax
Net Pay
Clear
Calculate
Exit
50
Implement as Program
  • Convert algorithm into program statements
  • Dim dTaxRate As Double
  • Dim dGrossPay As Double
  • Dim dUnionDues As Double
  • Dim dNetPay As Double
  • cTax dTaxRate dGrossPay
  • dNetPay dGrossPay - (dTax dUnionDues)

51
Implement as Program
  • Implement design in VB
  • Add methods for cmdCalc, cmdClear and cmdExit
  • Note cmdCalcs method essentially implements the
    algorithm you have devised

52
Implement as Program
  • Okay
  • Go to it!
Write a Comment
User Comments (0)
About PowerShow.com