Variables and Expressions - PowerPoint PPT Presentation

1 / 39
About This Presentation
Title:

Variables and Expressions

Description:

Financial Annuity Functions. Pmt is a function for determining monthly payments. ... of an expression is to perform a calculation for an assignment statement. ... – PowerPoint PPT presentation

Number of Views:51
Avg rating:3.0/5.0
Slides: 40
Provided by: business64
Category:

less

Transcript and Presenter's Notes

Title: Variables and Expressions


1
Variables and Expressions
7
  • Programming Right from the Start with Visual
    Basic .NET 1/e

2
Objectives
  • Distinguish between Numeric, String, Char,
    Boolean, Date, and Object data types
  • Explain the similarities and differences between
    variables and constants
  • Understand and use the Dim and Const statements
  • Understand and use arithmetic, comparison, and
    logical operators

3
Objectives (cont.)
  • Explain the advantages of intrinsic functions for
    performing common calculations
  • Understand and effectively use the TextBox,
    ListBox, and ComboBox controls
  • Successfully write Windows applications involving
    calculations that require complex expressions and
    intrinsic functions

4
7-1 Data Types
  • A variable is a storage location that can be
    accessed and changed by developer code.
  • A variable has a name and an associated data
    value.
  • A variable has a data type that determines the
    kind of data values the variable can store.

5
Numeric Types
  • Numeric types have two classes
  • Integral data types are those that represent only
    whole numbers.
  • Integer is the most common.
  • Floating-point data types are those that
    represent numbers with both integer and
    fractional parts.
  • Double is the most common.

6
String and Char Types
  • The Char data type stores a single character in
    Unicode format.
  • The String data type stores a sequence of Unicode
    characters.
  • Unicode is a 16-bit international character
    encoding system that covers values for more than
    45,000 characters.
  • The first 128 characters correspond to the ASCII
    (American Standard Code for Information
    Interchange) character set.

7
Boolean, Data, and Object Types
  • The Boolean data type is an unsigned value that
    is interpreted as either true or false.
  • The Date data type stores a date and time value
    that includes second, minute, hour, day, month,
    and year values.
  • The Object data type is the universal data type
    in VB. NET.

8
7-2 The Dim Statement
  • Variables are declared with the Dim statement
    (short for Dimension statement).
  • One or more variables can be declared with a
    single Dim statement.
  • The Dim statement can be used to specify the
    variables initial value by placing an equal sign
    after the data type.

9
Naming Rules for Variables
  • A variable must have a unique name, called an
    identifier.
  • Identifiers must follow three rules
  • Begin with a letter or underscore
  • Contain only letters, digits, and underscores
  • Cannot be reserved words
  • Dim identifier , identifier As datatype
    initialvalue

10
Working with Constants
  • A constant is a storage location whose value
    cannot change during the execution of the
    program.
  • Constants are declared with the Const
    declaration.
  • Const identifier As datatype value

11
7-3 Operators and Expressions
  • An operator is a symbol that indicates an action
    to be performed.
  • Value-returning code elements such as variables,
    constants, and expressions can be combined with
    one or more operators to form an expression.

12
Arithmetic andString Operators
  • Arithmetic operators require numeric operands and
    produce numeric results.
  • The string operator concatenation () requires
    String operands and produces a String result such
    as
  • S sun set
  • S becomes sunset

13
Comparison Operators
  • Comparison operators require numeric operands and
    produce a logical result.
  • Greater than gt
  • Less than lt
  • Greater than or equal gt
  • Less than or equal lt
  • Equal
  • Not equal ltgt

14
Logical Operators
  • Logical Operators require logical operands and
    produce a logical result.
  • NOT Logical opposite
  • AND Both values are true
  • OR At least one value is true
  • XOR Exactly one value is true

15
Operator Precedence
  • When several operations occur in an expression,
    each part is evaluated and resolved in a
    predetermined order called operator precedence.
  • First Evaluate all arithmetic/concatenation
    operators
  • Second Evaluate all comparison operators
  • Third Evaluate all logical operators

16
7-4 The Assignment Statement
  • An assignment statement is used to store a value
    into a variable or an object property.
  • variable expression
  • object.property expression
  • The equal sign () is the assignment operator.

17
7-5 Intrinsic Functions
  • VB .NET provides a large number of intrinsic
    functions to improve developer productivity.
  • Intrinsic functions support a broad range of
    activities, including math calculations, business
    calculations, time and date functions, string
    formatting functions, and many more.

18
Simple Functions
19
Financial Annuity Functions
  • Pmt is a function for determining monthly
    payments.
  • Pmt(Rate, NPer, PV)
  • FV is a function for determining the future value
    of an annuity based on periodic, fixed payments
    and a fixed interest rate.
  • FV(Rate, NPer, Pmt)

20
7-6 InputBox and MsgBox
  • InputBox and MsgBox are intrinsic functions that
    facilitate communication with the user by means
    of a dialog box.
  • A dialog box is a pop-up window that informs the
    user of some information or accepts information
    from the user.

21
The InputBox Function
  • The InputBox function is a simple means for
    prompting the user for keyboard input.
  • Result InputBox(prompt, title)
  • When executed, InputBox displays a dialog box
    containing the specified prompt and a text box.

22
The MsgBox Function
  • The MsgBox function displays a message in a
    dialog box.
  • MsgBox(prompt)
  • The prompt argument is a string expression that
    gets displayed as the message in the dialog box.

23
The MsgBox Function (cont.)
24
7-7 TextBox Control
  • The TextBox control provides an area for the user
    to enter data while the program is executing.
  • TextBox controls can be used to display output on
    the form.

25
TextBox Properties
26
TextBox Methods
27
7-8 ListBox Control
  • The ListBox control makes a visible list of
    items.
  • The user can select items in the list using mouse
    clicks.

28
ListBox Properties
29
ListBox Methods
30
ListBox IllustratedSelect Ice Cream Toppings
  • The scroll bar is automatically created by VB.
    NET if the number of items in the list is too big
    for the display size of the list box.
  • Double-click on an item in the first list box to
    add the item to the second list box.
  • Double-click on an item in the second list box to
    remove that item.

31
7-9 ComboBox Control
  • The ComboBox control combines the functionality
    of the TextBox and ListBox controls.
  • The user can select values from the drop-down
    list or enter values directly into the text box
    area.

32
ComboBox Properties
33
ComboBox IllustratedMovie Voting
  • Select a movie from each combo box, then press
    the vote button.
  • The default DropDownStyle property value is
    DropDown, which makes the text box editable.
  • Change the first combo boxs DropDown-Style
    property to DropDownList and rerun the
    application.

34
Chapter Summary
  • A variable is a storage location that can be
    accessed and changed by developer code.
  • A constant is a storage location with a name and
    an associated data value.
  • A data type specifies the kind of data that a
    storage location can hold.
  • The unique name for a variable, constant, object,
    or subroutine is called an identifier.

35
Chapter Summary (cont.)
  • It is good practice to make variable names
    descriptive with mixed case.
  • The Dim statement is used to declare a variable
    by specifying its name and data type.
  • Expressions are combinations of operators and
    value-returning code elements such as variables,
    constants, and literals.

36
Chapter Summary (cont.)
  • One of the common uses of an expression is to
    perform a calculation for an assignment
    statement.
  • The process of changing a value from one data
    type to another is called conversion.
  • Pmt is an intrinsic function that returns the
    payment for a loan based on periodic, constant
    payments and a constant interest rate.

37
Chapter Summary (cont.)
  • For a program to be useful, it must perform some
    type of input/output.
  • A TextBox control provides GUI form input by
    providing an area on the form where the user can
    enter data while the program is executing.

38
Chapter Summary (cont.)
  • A ListBox control provides GUI form input as a
    list of items that the user can select by
    clicking.
  • A ComboBox control combines the functionality of
    the TextBox and ListBox controls.

39
Variables andExpressions
7
  • Programming Right from the Start with Visual
    Basic .NET 1/e
Write a Comment
User Comments (0)
About PowerShow.com