1. Trang chủ
  2. » Công Nghệ Thông Tin

Lecture Learning programming using Visual Basic Net – Chapter 4 Performing calculations and manipulating data Expressions

28 268 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 28
Dung lượng 369,5 KB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

Chapter 4 Performing calculations and manipulating data Expressions. The following will be discussed in this chapter Describe the operators and functions used to create arithmetic, string, and logical expressions; explain why errors occur and how to avoid them; write logical expressions using comparison operators and logical operators.

Trang 1

CHAPTER FOUR

Performing Calculations and Manipulating Data: Expressions

Trang 3

McGraw Hill/Irwin ©2002 by The McGraw-Hill Companies, Inc All rights

reserved.

Objectives

• Describe the operators and functions used to

create arithmetic, string, and logical expressions

• Explain why errors occur and how to avoid them

• Write logical expressions using comparison

operators and logical operators

Trang 4

4.1 Using Expressions, Operators, and

Functions in Visual Basic NET Statements

• An expression tells the computer to manipulate

Trang 5

McGraw Hill/Irwin ©2002 by The McGraw-Hill Companies, Inc All rights

reserved.

4.1 Using Expressions, Operators, and

Functions in Visual Basic NET Statements

(cont.)

• Statements

– Perform various tasks

• Evaluate expressions one at a time.

• Carry out tasks specified in expressions.

Trang 6

4.1 Using Expressions, Operators, and

Functions in Visual Basic NET Statements

(cont.)

• Expressions

– Single values or a combination of values,

operators, and/or functions that reduce to a single value.

– Evaluated by calculation or manipulation.

– Result in numeric, string, or Boolean values.

Trang 7

McGraw Hill/Irwin ©2002 by The McGraw-Hill Companies, Inc All rights

reserved.

4.1 Using Expressions, Operators, and

Functions in Visual Basic NET Statements

Trang 8

4.1 Using Expressions, Operators, and

Functions in Visual Basic NET Statements

(cont.)

• Functions

– Descriptive names that specify a more complex

operation than that performed by an operator.

– Names are always followed by parentheses.

– The value between the parentheses is called the argument.

– The resulting value is called the return value.

Trang 9

McGraw Hill/Irwin ©2002 by The McGraw-Hill Companies, Inc All rights

reserved.

4.1 Using Expressions, Operators, and

Functions in Visual Basic NET Statements

(cont.)

• More Complicated Expressions

– Operators and functions can be composed into

complicated expressions.

– A function’s argument may be complex.

• Ex X = Math.Sqrt(10 + Math.Sqrt(Y + 29))

Trang 10

4.1 Using Expressions, Operators, and

Functions in Visual Basic NET Statements

(cont.)

• Expressions as a Part of Statements

– An expression is always a part of a statement.

• Ex Z = Math.Sqrt(X + 2 + Y) + Math.Sqrt(4)

Trang 11

McGraw Hill/Irwin ©2002 by The McGraw-Hill Companies, Inc All rights

reserved.

4.2 Arithmetic Expressions

• Arithmetic operators and functions must be

written according to Visual Basic NET syntax

Trang 12

4.2 Arithmetic Expressions (cont.)

• Arithmetic Operators and Operator Precedence

– Arithmetic operations must adhere to the

Trang 13

McGraw Hill/Irwin ©2002 by The McGraw-Hill Companies, Inc All rights

Trang 14

4.2 Arithmetic Expressions (cont.)

Trang 15

McGraw Hill/Irwin ©2002 by The McGraw-Hill Companies, Inc All rights

reserved.

4.2 Arithmetic Expressions (cont.)

• Type Conversion Functions

– A number of functions will convert values from

one type to another.

Trang 16

4.2 Arithmetic Expressions (cont.)

• Avoiding Arithmetic Errors

– We must write arithmetic expressions carefully.

– We must avoid certain pitfalls.

Trang 17

McGraw Hill/Irwin ©2002 by The McGraw-Hill Companies, Inc All rights

reserved.

4.2 Arithmetic Expressions (cont.)

– Problems Caused by Limited Significant Digits

• Limitations on the number of significant digits.

• Digits may be loss at run time.

Trang 18

4.3 String Expressions

• Manipulate strings using string operators and

functions

– String Operators

• & is the only string operator in Visual Basic NET.

• Joining two string values is called concatenation.

– Functions Used with Strings

• Format()

– Converts a numeric value to a string and formats it.

• Left(), Right(), and Mid()

Trang 19

McGraw Hill/Irwin ©2002 by The McGraw-Hill Companies, Inc All rights

• LTrim(), Rtrim(), and Trim()

– Remove leading and trailing spaces.

Trang 21

McGraw Hill/Irwin ©2002 by The McGraw-Hill Companies, Inc All rights

reserved.

4.4 The Try/Catch Block Revisited

• Used to detect and respond to error conditions

• Can handle multiple error conditions

Trang 22

4.6 Logical Expressions

• Used to select an action from alternative actions

• Results in a True or False answer to a test

• Also known as Boolean expressions

Trang 23

McGraw Hill/Irwin ©2002 by The McGraw-Hill Companies, Inc All rights

Trang 24

4.6 Logical Expressions (cont.)

– Logical Functions

• Common ones are IsNumeric() and IIf().

• IsNumeric() is True if the argument is a valid number.

• IIf() chooses between two alternate paths.

Trang 25

McGraw Hill/Irwin ©2002 by The McGraw-Hill Companies, Inc All rights

reserved.

Chapter Summary

• Expressions are part of a statement

• Expressions can be numeric, string, or logical

• Expressions consist of constants, variables,

operators, and functions

• An operator is a symbol that specifies a simple

operation

Trang 26

Chapter Summary (cont.)

• A function is a name that represents a complex

operation

• Function names always end in parentheses

• Arithmetic expressions consists of numeric

constants, variables, arithmetic operators, and

functions

• Arithmetic expressions are evaluated using

order of precedence rules

Trang 27

McGraw Hill/Irwin ©2002 by The McGraw-Hill Companies, Inc All rights

reserved.

Chapter Summary (cont.)

• Errors may occur when evaluating expressions

• String expressions consist of string constants

and variables and string operators and functions

• Chr() and Asc() are used with strings to access

the ANSI table

• Logical expressions are composed of variables, constants, comparison operators, logical

operators, and logical functions

Trang 28

Chapter Summary (cont.)

• A logical expression has the form of a

True/False question

• Comparison of numeric values is

straightforward

• Comparison of string values is more complex

• The logical function IIf() is used to choose one of two expressions

Ngày đăng: 16/05/2017, 14:41

TỪ KHÓA LIÊN QUAN

TÀI LIỆU CÙNG NGƯỜI DÙNG

TÀI LIỆU LIÊN QUAN