Chapter 3: Introducing the Microsoft.NET Framework and Visual Basic.NET Visual Basic.NET Programming: From Problem Analysis to Program Design.

Slides:



Advertisements
Similar presentations
Operators & Identifiers The Data Elements. Arithmetic Operators exponentiation multiplication division ( real ) division ( integer quotient ) division.
Advertisements

L2:CSC © Dr. Basheer M. Nasef Lecture #2 By Dr. Basheer M. Nasef.
Chapter 3: Using Variables and Constants Programming with Microsoft Visual Basic 2005, Third Edition.
Lecture Set 4 Data Types and Variables Part B – Variables, Constants, Expressions Conversion Rules Options Strict, Option Explicit Scope of Definition.
Types and Arithmetic Operators
1.
Primitive Data Types and Operations. Introducing Programming with an Example public class ComputeArea { /** Main method */ public static void main(String[]
Bellevue University CIS 205: Introduction to Programming Using C++ Lecture 3: Primitive Data Types.
1 9/20/06CS150 Introduction to Computer Science 1 Review: Exam 1.
Fundamental Programming Structures in Java: Comments, Data Types, Variables, Assignments, Operators.
VB .NET Programming Fundamentals
Basic Elements of C++ Chapter 2.
Introduction to C++ Programming
Variables & Math Operators CE 311 K - Introduction to Computer Methods Daene C. McKinney.
© The McGraw-Hill Companies, 2006 Chapter 1 The first step.
A First Book of ANSI C Fourth Edition
Liang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. All rights reserved. 1 Chapter 2 Elementary Programming.
 2003 Prentice Hall, Inc. All rights reserved. 1 Introduction to C++ Programming Outline Introduction to C++ Programming A Simple Program: Printing a.
Module 1: Introduction to C# Module 2: Variables and Data Types
Chapter 2 Primitive Data Types and Operations F Introduce Programming with an Example  The MyInput class F Identifiers, Variables, and Constants F Primitive.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
Chapter 3 Processing and Interactive Input. 2 Assignment  The general syntax for an assignment statement is variable = operand; The operand to the right.
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
Input, Output, and Processing
Chapter 2: Using Data.
Chapter 9: Writing Procedures Visual Basic.NET Programming: From Problem Analysis to Program Design.
CHAPTER 4: CONTROL STRUCTURES - SEQUENCING 10/14/2014 PROBLEM SOLVING & ALGORITHM (DCT 1123)
Java Programming: From Problem Analysis to Program Design, 4e Chapter 2 Basic Elements of Java.
Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 3 Variables, Constants, Methods, and Calculations.
1 Chapter 3 Syntax, Errors, and Debugging Fundamentals of Java: AP Computer Science Essentials, 4th Edition Lambert / Osborne.
Introduction to Visual Basic Programming. Introduction Simple Program: Printing a Line of Text Another Simple Program: Adding Integers Memory Concepts.
Chapter 3 Syntax, Errors, and Debugging Fundamentals of Java.
Variables & Function Calls. Overview u Variables  Programmer Defined & Intrinsic  Data Types  Calculation issues u Using Functions  The val() function.
Microsoft Visual Basic 2010: Reloaded Fourth Edition Chapter Three Memory Locations and Calculations.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 2A Reading, Processing and Displaying Data (Concepts)
Programming with Microsoft Visual Basic th Edition
C++ for Engineers and Scientists Second Edition
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
Chapter 3: Introducing the Microsoft.NET Framework and Visual Basic.NET Visual Basic.NET Programming: From Problem Analysis to Program Design.
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Elementary Programming.
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.
Chapter 4: Variables, Constants, and Arithmetic Operators Introduction to Programming with C++ Fourth Edition.
Introduction to Algorithmic Processes CMPSC 201C Fall 2000.
Making Interactive Programs with Visual Basic .NET
Slide 1 Chapter 3 Variables  A variable is a name for a value stored in memory.  Variables are used in programs so that values can be represented with.
© 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.
1Object-Oriented Program Development Using C++ Built-in Data Types Data type –Range of values –Set of operations on those values Literal: refers to acceptable.
Lecture 3: More Java Basics Michael Hsu CSULA. Recall From Lecture Two  Write a basic program in Java  The process of writing, compiling, and running.
CSIT 108 Review Visual Basic.NET Programming: From Problem Analysis to Program Design.
Bill Tucker Austin Community College COSC 1315
IS 350 Numeric Data Types.
Egyptian Language School Computer Department
Topics Designing a Program Input, Processing, and Output
BASIC ELEMENTS OF A COMPUTER PROGRAM
Visual Basic Variables
Revision Lecture
Lecture Set 4 Data Types and Variables
Advanced Programming Lecture 02: Introduction to C# Apps
CIS16 Application Development Programming with Visual Basic
Chapter 2 Variables.
Topics Designing a Program Input, Processing, and Output
Topics Designing a Program Input, Processing, and Output
Fundamental OOP Programming Structures in Java: Comments, Data Types, Variables, Assignments, Operators.
In this class, we will cover:
Primitive Types and Expressions
Chapter 2 Primitive Data Types and Operations
Presentation transcript:

Chapter 3: Introducing the Microsoft.NET Framework and Visual Basic.NET Visual Basic.NET Programming: From Problem Analysis to Program Design

Visual Basic.NET Programming: From Problem Analysis to Program Design2 Objectives Explore the Microsoft.NET Framework Write a Visual Basic.NET module definition Define Visual Basic.NET variables and data types Write basic computational statements Read input from the keyboard

Visual Basic.NET Programming: From Problem Analysis to Program Design3 Exploring the Microsoft.NET Framework.NET Framework key parts: –Compilers for: VB.NET Other supported.NET languages –Common Language Runtime (CLR) –Framework Class Library (FCL)

Visual Basic.NET Programming: From Problem Analysis to Program Design4

5 The Microsoft.NET Compilers Includes compilers for: –VB –C++ –C# –J# –COBOL

Visual Basic.NET Programming: From Problem Analysis to Program Design6 The Microsoft.NET Compilers (continued) Compiler has two primary purposes: –Check source code for valid syntax –Translate it into executable form Compilers translate source code into language called Microsoft Intermediate Language (MSIL) –Language used by CLR –CLR translates IL into executable code

Visual Basic.NET Programming: From Problem Analysis to Program Design7 The Common Language Runtime Responsibility: –Connect IL files coming from various.NET compilers –Translate these into executable files –Manage execution of code in file

Visual Basic.NET Programming: From Problem Analysis to Program Design8

9 The Common Language Runtime (continued) CLR consists of –Common Type System (CTS) –Common Language Specification (CLS) –Just-In-Time (JIT) compiler Allocates and reclaims memory while application running

Visual Basic.NET Programming: From Problem Analysis to Program Design10 The Framework Class Library Assembly –File containing IL –Each contains one or more classes FLC –Consists of approximately 100 assemblies –Have suffix of.dll Members –Methods and attributes in.NET classes

Visual Basic.NET Programming: From Problem Analysis to Program Design11 The Framework Class Library (continued) Namespaces –Organize classes –Can contain both classes and other namespaces –Compilers do not automatically search all namespaces for classes used by code Must use keyword Imports Tell compiler specific namespaces to access

Visual Basic.NET Programming: From Problem Analysis to Program Design12

Visual Basic.NET Programming: From Problem Analysis to Program Design13

Visual Basic.NET Programming: From Problem Analysis to Program Design14 Writing a Visual Basic.NET Module Definition Module definition –Begins with keyword Module –Ends with keyword End Module Statements contain: –Keywords –Identifiers

Visual Basic.NET Programming: From Problem Analysis to Program Design15 Writing a Visual Basic.NET Module Definition (continued) Identifier –Name assigned to things such as: Modules Procedures Variables

Visual Basic.NET Programming: From Problem Analysis to Program Design16 Writing a Visual Basic.NET Module Definition (continued) Identifier naming rules: –Can be up to 1023 characters long –Can include any: Letter Number Underscore character No spaces –Cannot begin with a number –Cannot be a keyword

Visual Basic.NET Programming: From Problem Analysis to Program Design17 Writing a Visual Basic.NET Module Definition (continued) Code not case sensitive Comment lines –Add explanations to code –Ignored by compiler Module header –Names module –Syntax: Module modulename

Visual Basic.NET Programming: From Problem Analysis to Program Design18 Writing a Visual Basic.NET Module Definition (continued) Procedure: –Contains statements that perform processing –Types: Sub Function –Begin with header Procedure Main invoked automatically

Visual Basic.NET Programming: From Problem Analysis to Program Design19 Writing a Visual Basic.NET Module Definition (continued) Argument –Information contained in parentheses when calling procedure –Passed to procedure Literal –Value defined within a statement

Visual Basic.NET Programming: From Problem Analysis to Program Design20 Defining Visual Basic.NET Variables And Data Types Variable –Memory location that contains data –Characteristics: Name Data type Value

Visual Basic.NET Programming: From Problem Analysis to Program Design21 Understanding VB.NET Data Types Each variable has a data type Can be: –Primitive –Complex Unicode character set –Allocates two bytes for each character –Accommodates all characters of major international languages

Visual Basic.NET Programming: From Problem Analysis to Program Design22

Visual Basic.NET Programming: From Problem Analysis to Program Design23 Declaring and Populating Variables Declaration statements –Define variables Syntax: –Dim variablename As datatype Assignment operator –= –Assigns value on right side to variable named on left side

Visual Basic.NET Programming: From Problem Analysis to Program Design24 Example 3-2: Declaring Variables Dim myInteger As Integer Dim myDouble As Double Dim myBoolean As Boolean

Visual Basic.NET Programming: From Problem Analysis to Program Design25 Example 3-4: Populating Variables myInteger = 1 myDouble = 2.5

Visual Basic.NET Programming: From Problem Analysis to Program Design26 Defining Constants Constant –Variable with a value that does not change –Contain values such as: Company name Tax identification number –Syntax: Const constantname As datatype –Must be initialized in the same statement that declares them

Visual Basic.NET Programming: From Problem Analysis to Program Design27 Defining Constants (continued) Naming convention: –Capitalize constant names –If name consists of more than one word Separate words with underscore character (_) –Example: TAX_ID

Visual Basic.NET Programming: From Problem Analysis to Program Design28 Converting Data Types Numeric data types have different capacities: –Byte variable can hold maximum value of 255 –Integer variable has maximum value of 2.1 billion Implicit type conversion –Use assignment operator to assign contents of variable to a variable with different data type

Visual Basic.NET Programming: From Problem Analysis to Program Design29 Example 3-7: Implicit Type Conversion Dim myInteger As Integer = 1 Dim myDouble As Double = 2.5 myDouble = myInteger Assign Integer value to Double variable –Data type Double has greater capacity than Integer –No potential loss of data

Visual Basic.NET Programming: From Problem Analysis to Program Design30 Example 3-8: Loss of Precision Loss of precision –Computing error that can occur when decimal positions are dropped Dim myInteger As Integer = 1 Dim myDouble As Double = 2.5 myInteger = myDouble VB.NET will automatically round decimal values before truncating

Visual Basic.NET Programming: From Problem Analysis to Program Design31 Example 3-8: Loss of Precision (continued) Option Strict –Prevent unintentional loss of precision when mixing data types in assignment statements –Compiler detects potential loss of precision Displays error message Explicit type conversion –Invoke Convert method to convert data types

Visual Basic.NET Programming: From Problem Analysis to Program Design32

Visual Basic.NET Programming: From Problem Analysis to Program Design33 Converting Data Types (continued) Option Explicit –Must define variable before using it in a statement –Otherwise Compiler generates error message –Generally set On

Visual Basic.NET Programming: From Problem Analysis to Program Design34 Using Reference Variables Uses class name as data type For example: –String Variable refers to or points to instance of class –Does not actually contain data –Contains memory address of instance of class that contains data

Visual Basic.NET Programming: From Problem Analysis to Program Design35

Visual Basic.NET Programming: From Problem Analysis to Program Design36 Writing Basic Computational Statements Concatenate operator –& –Joins two Strings Arithmetic operators –For multiplication, division, addition, and subtraction –*, /, +, -

Visual Basic.NET Programming: From Problem Analysis to Program Design37 Using the Arithmetic Operators Evaluated in predetermined order called precedence –Standard algebraic rules of precedence apply Other operators: –Exponentiation –Integer division –Remainder computation

Visual Basic.NET Programming: From Problem Analysis to Program Design38 Example 3-15: Integer Division (\) Dim firstInt As Integer = 11 Dim secondInt As Integer = 2 Dim integerResult As Integer = 0 integerResult = firstInt \ secondInt Console.WriteLine(“integerResult = firstInt \ secondInt: “ & integerResult) Sample Run: –integerResult = firstInt \ secondInt: 5

Visual Basic.NET Programming: From Problem Analysis to Program Design39

Visual Basic.NET Programming: From Problem Analysis to Program Design40 Using the Arithmetic Operators (continued) Assignment operators: –Formed by combining arithmetic operator with assignment operator –Example: i += 1

Visual Basic.NET Programming: From Problem Analysis to Program Design41 Invoking Methods in the Math Class System namespace includes Math class –Contains methods to accomplish Exponentiation Rounding Trigonometric calculations Use.NET Help facility to explore methods Invoke method: –Math.Pow(firstInt, secondInt)

Visual Basic.NET Programming: From Problem Analysis to Program Design42 Invoking Methods in the Math Class (continued) Math class constants: –PI –E –To access: Math.E

Visual Basic.NET Programming: From Problem Analysis to Program Design43 Reading Input From the Keyboard Use Console class –ReadLine method Read one or more characters from keyboard Convert any numeric data to desired data type Prompt –Message displayed to user asking for input

Visual Basic.NET Programming: From Problem Analysis to Program Design44 Programming Example: Temperature Converter Input –Fahrenheit temperature including decimal positions Output –Celsius temperature that corresponds to Fahrenheit temperature that was input Results rounded to one decimal position

Visual Basic.NET Programming: From Problem Analysis to Program Design45 Programming Example: Temperature Converter (continued) Main Algorithm –Declare variables –Prompt user for input –Invoke Console.ReadLine to input value from keyboard –Invoke Convert.ToDouble to convert data type String to Double

Visual Basic.NET Programming: From Problem Analysis to Program Design46 Programming Example: Temperature Converter (continued) Main Algorithm (continued) –Compute Celsius temperature –Invoke Math.Round to round computed value to one decimal position –Invoke Console.WriteLine to display rounded Celsius temperature

Visual Basic.NET Programming: From Problem Analysis to Program Design47 Summary Framework consists of: –Compilers –Common Language Runtime (CLR) –Framework Class Library (FCL) VB.NET statements consist of –Keywords –Identifiers

Visual Basic.NET Programming: From Problem Analysis to Program Design48 Summary (continued) Module –Main module executed automatically Procedures: –Subs –Functions Variable –Memory location that contains data

Visual Basic.NET Programming: From Problem Analysis to Program Design49 Summary (continued) Constant –Variable with value that does not change Reference variable –Uses class name as data type Operators: –Mathematic –Assignment