Introduction to Visual Basic - PowerPoint PPT Presentation

1 / 22
About This Presentation
Title:

Introduction to Visual Basic

Description:

Variables are named locations in memory that are reserved for the ... Class is a blueprint for which objects are created. An object is an instance of a class ... – PowerPoint PPT presentation

Number of Views:139
Avg rating:3.0/5.0
Slides: 23
Provided by: saxserv
Category:

less

Transcript and Presenter's Notes

Title: Introduction to Visual Basic


1
Introduction to Visual Basic
2
Objectives
  • Variables
  • Operations
  • Conditional Structure
  • Loop
  • Objects

3
Variables Examples
  • Variables are named locations in memory that are
    reserved for the duration of the program.
  • when the program terminates, so do all the
    variables.
  • Example
  • Dim Price As Integer
  • Price 150

4
Data Types
5
Examples
  • Dim MyName As String
  • MyName John
  • Dim MyName As String John

6
Arithmetic Operations
  • Addition
  • - Subtraction
  • Multiplication
  • / Division

7
Logical Operators
8
Logical Operators
9
Conditions
  • If Then
  • If grpInfo 1 Then
  • MsgBox Group is 1
  • End If
  • If ThenElse
  • If grpInfo 1 Then
  • MsgBox Group is 1
  • Else
  • MsgBox Select another form
  • End If

10
Example
  • If cond1 Then
  • If cond2 Then
  • action(s)
  • End If
  • End If
  • If cond1 And cond2 Then
  • action(s)
  • End If

This is easier to understand
A confusing If Block
11
The Select Case Block
  • Similar to If statement
  • Used instead of nested If statement
  • An action to be selected from a list of
    alternatives
  • Avoids confusion of deeply nested If blocks

12
Select Case Block (Syntax)
  • Select Case selector
  • Case value-list-1
  • action1
  • Case value-list-2
  • action2
  • ..
  • Case Else
  • action of last resort
  • End Select

13
Select Case Block
  • Each value-list contains one or more of the
    following types of items separated by a comma
  • a constant
  • a variable
  • an expression

14
Example of Select Case
  • Select Case letterGrade
  • Case A, B
  • M.text Good Work
  • Case C
  • M.text Average Work
  • Case Else
  • M.text Poor Work
  • End Select

15
The Do While . Loop
  • Do While condition is true
  • statement(s)
  • Loop

16
Flowchart for a Do While Loop
Is the condition true
No
Yes
Execute statements within the loop
Execute statements that follow the loop
17
The Do While . Loop
  • Is executed as long as the condition is True.
  • If condition is False then the next statement
    after the Loop is executed.

18
Object-oriented Programming
  • Objects
  • An object is a self-contained entity that is
    characterized by a recognizable set of
    characteristics and behavior.
  • Objects should have properties and methods

19
Class and Object
  • Class is a blueprint for which objects are
    created
  • An object is an instance of a class

20
Properties
  • Properties are characteristics of an object that
    determine the object
  • Examples
  • People
  • Window
  • Form
  • DoCmd

21
Method
  • Methods are actions that objects can take
  • Example
  • Dim MyString As String This is a test string
  • MyString MyString.Trim() This is a test
    string
  • MyString MyString.Substring(0, 4) This
  • MyString MyString.ToUpper() THIS
  • Dim Length As Integer MyString.Length 4

22
Create an Object
  • Create an instance of a class, or the object is
    instantiated
  • Syntax
  • Dim objName As New className
  • Example
  • Dim objWord As New Word.Application
  • Dim rsContacts As New ADODB.Recordset
Write a Comment
User Comments (0)
About PowerShow.com