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

Slides:



Advertisements
Similar presentations
Working with Intrinsic Controls and ActiveX Controls
Advertisements

Operators & Identifiers The Data Elements. Arithmetic Operators exponentiation multiplication division ( real ) division ( integer quotient ) division.
Chapter 3: Using Variables and Constants Programming with Microsoft Visual Basic 2005, Third Edition.
Objectives Understand the software development lifecycle Perform calculations Use decision structures Perform data validation Use logical operators Use.
Data Types and Expressions
Chapter 2: Using Data.
Bellevue University CIS 205: Introduction to Programming Using C++ Lecture 3: Primitive Data Types.
Input Validation Check the values entered into a text box before beginning any calculations Validation is a form of ‘self-protection’, rejecting bad data.
CSC110 Fall Chapter 5: Decision Visual Basic.NET.
An Introduction to Programming with C++ Fifth Edition Chapter 4 Chapter 4: Variables, Constants, and Arithmetic Operators.
Data types and variables
An Introduction to Programming with C++ Fifth Edition Chapter 4 Chapter 4: Variables, Constants, and Arithmetic Operators.
JavaScript, Fourth Edition
Chapter 2 Data Types, Declarations, and Displays
JavaScript, Third Edition
Repeating Program Instructions Chapter Microsoft Visual Basic.NET: Reloaded 1.
Chapter Three Using Variables and Constants Programming with Microsoft Visual Basic th Edition.
1 Chapter Two Using Data. 2 Objectives Learn about variable types and how to declare variables Learn how to display variable values Learn about the integral.
Objectives You should be able to describe: Data Types
Variables and Constants
Chapter 3: Using Variables and Constants
Programming with Microsoft Visual Basic th Edition CHAPTER THREE USING VARIABLES AND CONSTANTS.
Java Primitives The Smallest Building Blocks of the Language (corresponds with Chapter 2)
1 Κατανεμημένες Διαδικτυακές Εφαρμογές Πολυμέσων Γιάννης Πετράκης.
Copyright © 2008 Pearson Prentice Hall. All rights reserved. 1 Microsoft Office Excel Copyright © 2008 Pearson Prentice Hall. All rights reserved
1 Do you have a CS account? Primitive types –“ building blocks ” for more complicated types Java is strongly typed –All variables in a Java program must.
Chapter 4: The Selection Structure
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 4 Working with Variables, Constants, Data Types, and Expressions.
Visual Basic.NET BASICS Lesson 4 Mathematical Operators.
CH2 – Using Data. Constant Something which cannot be changed Data Type Format and size of a data item Intrinsic Data Types Pg. 47 – Table 2-1 Basic ones.
Chapter 2: Using Data.
Computer Programming TCP1224 Chapter 4 Variables, Constants, and Arithmetic Operators.
Microsoft Visual Basic 2005 CHAPTER 4 Variables and Arithmetic Operations.
Data & Data Types & Simple Math Operation 1 Data and Data Type Standard I/O Simple Math operation.
Introduction to Programming with RAPTOR
Operators & Identifiers The Data Elements. Arithmetic Operators exponentiation multiplication division ( real ) division ( integer quotient ) division.
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 3 Variables, Constants, Methods, and Calculations.
Variables & Function Calls. Overview u Variables  Programmer Defined & Intrinsic  Data Types  Calculation issues u Using Functions  The val() function.
1 Scripting Languages VBScript - Recognized mainly by Internet Explorer only - Netscape does have a plug-in JavaScript - Recognized by Internet Explorer.
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 4 Working with Variables, Constants, Data Types, and Expressions.
Programming with Microsoft Visual Basic 2008 Fourth Edition Chapter Three Using Variables and Constants.
Visual Basic 2010 How to Program © by Pearson Education, Inc. All Rights Reserved.1.
Programming with Microsoft Visual Basic th Edition
Tutorial 3: Using Variables and Constants1 Tutorial 3 Using Variables and Constants.
Part:2.  Keywords are words with special meaning in JavaScript  Keyword var ◦ Used to declare the names of variables ◦ A variable is a location in the.
Module B - Computation1/61 Module-B-Computation Variables Basic Memory Operations Expressions.
Chapter 4 Getting Started with VBA. Subroutines Subroutine is the logical section of code that performs a particular task. Subroutine is also called a.
Variables in VB.NET. Variables  A storage location in memory (RAM)  Holds data/information while the program is running  These storage locations can.
Microsoft Visual Basic 2012 CHAPTER FOUR Variables and Arithmetic Operations.
Creation of Variables with Numeric, alphanumeric, date, picture, memo data types Constant - A quantity that does not change during the execution of a program.
1 1 Chapter 2 Elementary Programming. 2 2 Motivations In the preceding chapter, you learned how to create, compile, and run a Java program. Starting from.
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 5 Decision Making.
Chapter 4: Variables, Constants, and Arithmetic Operators Introduction to Programming with C++ Fourth Edition.
Chapter 4 Chapter 4: Variables, Constants, and Arithmetic Operators.
Programming with Microsoft Visual Basic 2012 Chapter 3: Using Variables and Constants.
© 2006 Lawrenceville Press Slide 1 Chapter 4 Variables  A variable is a name for a value stored in memory.  Variables are created using a declaration.
Slide 1 Chapter 3 Variables  A variable is a name for a value stored in memory.  Variables are created using a declaration statement. For example: Dim.
Visual Basic/ Visual Studio Brandon Large. Connecting to prior knowledge In your notes write down what the two main parts of the computer are. The “software”
Chapter 2 Variables and Constants. Objectives Explain the different integer variable types used in C++. Declare, name, and initialize variables. Use character.
A variable is a name for a value stored in memory.
Chapter 3: Using Variables and Constants
Repeating Program Instructions
Variables and Arithmetic Operations
Microsoft Visual Basic 2005: Reloaded Second Edition
Visual Basic Programming Chapter Four Notes Working with Variables, Constants, Data Types, and Expressions GROUPBOX CONTROL The _____________________________________.
CIS 16 Application Development Programming with Visual Basic
An Introduction to Programming with C++ Fifth Edition
Chapter 2 Primitive Data Types and Operations
Variables and Constants
Programming Fundamental-1
Presentation transcript:

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

Crews/Murphy – Programming Right from the Start with Visual Basic.NET 1/e – ©2004 Prentice Hall 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

Crews/Murphy – Programming Right from the Start with Visual Basic.NET 1/e – ©2004 Prentice Hall 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

Crews/Murphy – Programming Right from the Start with Visual Basic.NET 1/e – ©2004 Prentice Hall 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.

Crews/Murphy – Programming Right from the Start with Visual Basic.NET 1/e – ©2004 Prentice Hall 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.

Crews/Murphy – Programming Right from the Start with Visual Basic.NET 1/e – ©2004 Prentice Hall 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.

Crews/Murphy – Programming Right from the Start with Visual Basic.NET 1/e – ©2004 Prentice Hall 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.

Crews/Murphy – Programming Right from the Start with Visual Basic.NET 1/e – ©2004 Prentice Hall 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 variable’s initial value by placing an equal sign after the data type.

Crews/Murphy – Programming Right from the Start with Visual Basic.NET 1/e – ©2004 Prentice Hall 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]]

Crews/Murphy – Programming Right from the Start with Visual Basic.NET 1/e – ©2004 Prentice Hall 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

Crews/Murphy – Programming Right from the Start with Visual Basic.NET 1/e – ©2004 Prentice Hall 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.

Crews/Murphy – Programming Right from the Start with Visual Basic.NET 1/e – ©2004 Prentice Hall 12 Arithmetic and String 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”

Crews/Murphy – Programming Right from the Start with Visual Basic.NET 1/e – ©2004 Prentice Hall 13 Comparison Operators Comparison operators require numeric operands and produce a logical result. –Greater than> –Less than< –Greater than or equal>= –Less than or equal<= –Equal= –Not equal <>

Crews/Murphy – Programming Right from the Start with Visual Basic.NET 1/e – ©2004 Prentice Hall 14 Logical Operators Logical Operators require logical operands and produce a logical result. –NOTLogical opposite –ANDBoth values are true –ORAt least one value is true –XORExactly one value is true

Crews/Murphy – Programming Right from the Start with Visual Basic.NET 1/e – ©2004 Prentice Hall 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

Crews/Murphy – Programming Right from the Start with Visual Basic.NET 1/e – ©2004 Prentice Hall 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.

Crews/Murphy – Programming Right from the Start with Visual Basic.NET 1/e – ©2004 Prentice Hall 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.

Crews/Murphy – Programming Right from the Start with Visual Basic.NET 1/e – ©2004 Prentice Hall 18 Simple Functions

Crews/Murphy – Programming Right from the Start with Visual Basic.NET 1/e – ©2004 Prentice Hall 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)

Crews/Murphy – Programming Right from the Start with Visual Basic.NET 1/e – ©2004 Prentice Hall 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.

Crews/Murphy – Programming Right from the Start with Visual Basic.NET 1/e – ©2004 Prentice Hall 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.

Crews/Murphy – Programming Right from the Start with Visual Basic.NET 1/e – ©2004 Prentice Hall 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.

Crews/Murphy – Programming Right from the Start with Visual Basic.NET 1/e – ©2004 Prentice Hall 23 The MsgBox Function (cont.)

Crews/Murphy – Programming Right from the Start with Visual Basic.NET 1/e – ©2004 Prentice Hall 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.

Crews/Murphy – Programming Right from the Start with Visual Basic.NET 1/e – ©2004 Prentice Hall 25 TextBox Properties

Crews/Murphy – Programming Right from the Start with Visual Basic.NET 1/e – ©2004 Prentice Hall 26 TextBox Methods

Crews/Murphy – Programming Right from the Start with Visual Basic.NET 1/e – ©2004 Prentice Hall ListBox Control The ListBox control makes a visible list of items. The user can select items in the list using mouse clicks.

Crews/Murphy – Programming Right from the Start with Visual Basic.NET 1/e – ©2004 Prentice Hall 28 ListBox Properties

Crews/Murphy – Programming Right from the Start with Visual Basic.NET 1/e – ©2004 Prentice Hall 29 ListBox Methods

Crews/Murphy – Programming Right from the Start with Visual Basic.NET 1/e – ©2004 Prentice Hall 30 ListBox Illustrated: Select 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.

Crews/Murphy – Programming Right from the Start with Visual Basic.NET 1/e – ©2004 Prentice Hall 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.

Crews/Murphy – Programming Right from the Start with Visual Basic.NET 1/e – ©2004 Prentice Hall 32 ComboBox Properties

Crews/Murphy – Programming Right from the Start with Visual Basic.NET 1/e – ©2004 Prentice Hall 33 ComboBox Illustrated: Movie 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 box’s DropDown- Style property to DropDownList and rerun the application.

Crews/Murphy – Programming Right from the Start with Visual Basic.NET 1/e – ©2004 Prentice Hall 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.

Crews/Murphy – Programming Right from the Start with Visual Basic.NET 1/e – ©2004 Prentice Hall 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.

Crews/Murphy – Programming Right from the Start with Visual Basic.NET 1/e – ©2004 Prentice Hall 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.

Crews/Murphy – Programming Right from the Start with Visual Basic.NET 1/e – ©2004 Prentice Hall 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.

Crews/Murphy – Programming Right from the Start with Visual Basic.NET 1/e – ©2004 Prentice Hall 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.

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