VB .NET Programming Fundamentals

Slides:



Advertisements
Similar presentations
Arrays.
Advertisements

Operators & Identifiers The Data Elements. Arithmetic Operators exponentiation multiplication division ( real ) division ( integer quotient ) division.
Lecture Set 4 Data Types and Variables Part B – Variables, Constants, Expressions Conversion Rules Options Strict, Option Explicit Scope of Definition.
Objectives Understand the software development lifecycle Perform calculations Use decision structures Perform data validation Use logical operators Use.
Primitive Data Types There are a number of common objects we encounter and are treated specially by almost any programming language These are called basic.
Data Types in Java Data is the information that a program has to work with. Data is of different types. The type of a piece of data tells Java what can.
Bellevue University CIS 205: Introduction to Programming Using C++ Lecture 3: Primitive Data Types.
VBA Modules, Functions, Variables, and Constants
Working with JavaScript. 2 Objectives Introducing JavaScript Inserting JavaScript into a Web Page File Writing Output to the Web Page Working with Variables.
1 Chapter 4 Language Fundamentals. 2 Identifiers Program parts such as packages, classes, and class members have names, which are formally known as identifiers.
CMT Programming Software Applications
Program Design and Development
Data types and variables
The Fundamentals of C++ Basic programming elements and concepts JPC and JWD © 2002 McGraw-Hill, Inc.
Fundamental Programming Structures in Java: Comments, Data Types, Variables, Assignments, Operators.
Chapter 2 Data Types, Declarations, and Displays
Chapter 3: Introducing the Microsoft.NET Framework and Visual Basic.NET Visual Basic.NET Programming: From Problem Analysis to Program Design.
Chapter 2 - Java Programming Fundamentals1 Chapter 2 Java Programming Fundamentals.
ASP.NET Programming with C# and SQL Server First Edition
JavaScript, Third Edition
Chapter 7: Working with Arrays
CSci 142 Data and Expressions. 2  Topics  Strings  Primitive data types  Using variables and constants  Expressions and operator precedence  Data.
Programming Concepts MIT - AITI. Variables l A variable is a name associated with a piece of data l Variables allow you to store and manipulate data in.
Basic Elements of C++ Chapter 2.
110-D1 Variables, Constants and Calculations(1) Chapter 3: we are familiar with VB IDE (building a form…) to make our applications more powerful, we need.
Objectives You should be able to describe: Data Types
A First Book of ANSI C Fourth Edition
 Value, Variable and Data Type  Type Conversion  Arithmetic Expression Evaluation  Scope of variable.
A Review of Programming and C++
 2006 Pearson Education, Inc. All rights reserved Arrays.
Language Elements 1. Data Types 2 Floating Point (real) Single Precision Double Precision Decimal Fixed Point (integer) Byte Short Integer Long Numerical.
XP Tutorial 10New Perspectives on Creating Web Pages with HTML, XHTML, and XML 1 Working with JavaScript Creating a Programmable Web Page for North Pole.
Hello.java Program Output 1 public class Hello { 2 public static void main( String [] args ) 3 { 4 System.out.println( “Hello!" ); 5 } // end method main.
The Fundamentals of C++ Chapter 2: Basic programming elements and concepts JPC and JWD © 2002 McGraw-Hill, Inc. Modified by S. Sudarshan.
Java Programming: From Problem Analysis to Program Design, 4e Chapter 2 Basic Elements of Java.
Operators & Identifiers The Data Elements. Arithmetic Operators exponentiation multiplication division ( real ) division ( integer quotient ) division.
Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition.
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 3 Variables, Constants, Methods, and Calculations.
Chapter 3 Functions, Events, and Control Structures JavaScript, Third Edition.
1 Chapter 3 Syntax, Errors, and Debugging Fundamentals of Java: AP Computer Science Essentials, 4th Edition Lambert / Osborne.
Chapter 3 Syntax, Errors, and Debugging Fundamentals of Java.
CNS 1120 Exam 1 Review. Programming Language Elements Syntax = the rules to follow Syntax = the rules to follow Semantics = the meaning of symbols Semantics.
Chapter 2 Variables.
Introduction to Programming Lecture Note - 2 Visual Basic Programming Fundamentals.
Programming in Java (COP 2250) Lecture 4 Chengyong Yang Fall, 2005.
VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 2A Reading, Processing and Displaying Data (Concepts)
 In the java programming language, a keyword is one of 50 reserved words which have a predefined meaning in the language; because of this,
CHAPTER 2 PROBLEM SOLVING USING C++ 1 C++ Programming PEG200/Saidatul Rahah.
C++ for Engineers and Scientists Second Edition
Chapter 1 Java Programming Review. Introduction Java is platform-independent, meaning that you can write a program once and run it anywhere. Java programs.
Chapter 3: Introducing the Microsoft.NET Framework and Visual Basic.NET Visual Basic.NET Programming: From Problem Analysis to Program Design.
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.
Windows Programming Lecture 03. Pointers and Arrays.
© 2004 Pearson Addison-Wesley. All rights reserved August 27, 2007 Primitive Data Types ComS 207: Programming I (in Java) Iowa State University, FALL 2007.
Java Programming: Guided Learning with Early Objects Chapter 1 Basic Elements of Java.
Chapter 2 Variables.
Visual Basic Variables
Primitive Data Types August 28, 2006 ComS 207: Programming I (in Java)
Data Types, Arithmetic Operations
Java Programming: From Problem Analysis to Program Design, 4e
An Object-Oriented Approach to Programming Logic and Design Fourth Edition Chapter 2 Applications and Data.
In this class, we will cover:
Chapter 2 Variables.
Fundamental OOP Programming Structures in Java: Comments, Data Types, Variables, Assignments, Operators.
In this class, we will cover:
In this class, we will cover:
Chapter 2 Variables.
Chapter 2 Primitive Data Types and Operations
Review of Java Fundamentals
The Fundamentals of C++
Presentation transcript:

VB .NET Programming Fundamentals Chapter 3 VB .NET Programming Fundamentals Object-Oriented Application Development Using VB .NET

Object-Oriented Application Development Using VB .NET Objectives In this chapter, you will: Learn about the VB .NET programming language Write a VB .NET module definition Use VB .NET variables and data types Compute with VB .NET Write decision-making statements Write loops Declare and access arrays Object-Oriented Application Development Using VB .NET

Object-Oriented Application Development Using VB .NET Introducing VB .NET VB .NET: Has achieved popularity and widespread acceptance Is a powerful, full-featured, object-oriented development language Is easy to learn and use Supports development of applications for networked environments Object-Oriented Application Development Using VB .NET

Object-Oriented Application Development Using VB .NET Introducing VB .NET By adopting the OO model, VB .NET encourages good software design Good software design can reduce: Debugging chores Maintenance chores Object-Oriented Application Development Using VB .NET

Writing a VB .NET Module Definition VB .NET code can be structured as a module definition, form definition, or class definition Module definition begins with “Module” and ends with “End Module” Form definition is used to create a GUI Class definition is written to represent an object Object-Oriented Application Development Using VB .NET

Writing a VB .NET Module Definition The VB .NET statements consist of keywords and identifiers Keywords have special meanings to VB .NET VB .NET identifiers are the names assigned by the programmer to modules, procedures, and variables, etc. VB .NET identifiers: Can be of any length Can include any letter or number, but no spaces Must begin with a letter of the alphabet Object-Oriented Application Development Using VB .NET

Writing a VB .NET Module Definition VB .NET code is not case sensitive VB .NET compiler does not require indentation of code, but good programming practice encourages indentation Comment lines: Add explanations to code Are ignored by compiler Begin with a single quote (') Object-Oriented Application Development Using VB .NET

Writing a VB .NET Module Definition Procedures begin with a procedure header, which identifies the procedure and describes some of its characteristics VB .NET has two types of procedures: Function and Sub A Function procedure can return a value A Sub procedure cannot return a value Object-Oriented Application Development Using VB .NET

Writing a VB .NET Module Definition Many statements invoke a method to do some work Information sent to a method is called an argument A literal is a value defined within a statement Object-Oriented Application Development Using VB .NET

Using VB. NET Variables and Data Types A variable: named memory location that can contain data All variables have: Data type – kind of data the variable can contain Name – An identifier the programmer creates to refer to the variable Value – Every variable refers to a memory location that contains data. This value can be specified by the programmer Object-Oriented Application Development Using VB .NET

Declaring and Initializing Variables Before declaring a variable, the programmer must specify its data type VB .NET has nine primitive data types: Data types for numeric data without decimals Byte, Short, Integer, Long Data types for numeric data with decimals Single, Double, Decimal Other data types Boolean, Char Object-Oriented Application Development Using VB .NET

Declaring and Initializing Variables To declare a VB .NET variable, write: Keyword “Dim” Name to be used for identifier Keyword “As” Data type Example: ' declare a variable Dim i As Integer Object-Oriented Application Development Using VB .NET

VB.NET Primitive Data Types Range of Value Size Numeric with no decimal Byte 0 to 255 8 bits Short -32768 to 32767 16 bits Integer 32 bits Long 64 bits Numeric with decimal Single Double Decimal 128 bits other Boolean True or False Char Any Unicode char Object-Oriented Application Development Using VB .NET

Declaring and Initializing Variables A value can be assigned by the programmer to a variable Assignment operator (=) assigns the value on the right to the variable named on the left side Example: ' populate the variable i = 1 Object-Oriented Application Development Using VB .NET

Declaring and Initializing Variables The code to both declare and initialize a variable can be written in one statement: ' declare a variable Dim i As Integer = 1 Several variables of the same data type can be declared in one statement: Dim x, y, z As Integer Object-Oriented Application Development Using VB .NET

Object-Oriented Application Development Using VB .NET Changing Data Types Option Strict helps prevent unintentional loss of precision when assigning values to variables If Option Strict is set to On, whenever an assignment statement that may result in a loss of precision is written, VB .NET compiler displays an error message Object-Oriented Application Development Using VB .NET

Object-Oriented Application Development Using VB .NET Changing Data Types With Option Explicit On, the programmer must define a variable before using it in a statement Option Explicit is generally set to On Object-Oriented Application Development Using VB .NET

Object-Oriented Application Development Using VB .NET Using Constants Constant: variable with a value that does not change Code to declare a constant is identical to the code to declare a variable, except: Keyword “Const” is used instead of “Dim” Constants must be initialized in the statement that declares them By convention, constant names are capitalized Object-Oriented Application Development Using VB .NET

Using Reference Variables There are two kinds of variables Primitive variable Declared with a primitive data type Contains the data the programmer puts there Reference variable Uses a class name as a data type Refers to or points to an instance of that class Does not contain the data; instead, it refers to an instance of a class that contains the data Object-Oriented Application Development Using VB .NET

Using Reference Variables Object-Oriented Application Development Using VB .NET

Object-Oriented Application Development Using VB .NET Computing with VB .NET VB .NET uses: Arithmetic operators (+, –, *, /) for addition, subtraction, multiplication, and division Parentheses to group parts of an expression and establish precedence Remainder operator (Mod) produces a remainder resulting from the division of two integers Integer division operator (\) to produce an integer result Caret (^) for exponentiation Object-Oriented Application Development Using VB .NET

Object-Oriented Application Development Using VB .NET Computing with VB .NET Math class contains methods to accomplish exponentiation, rounding, and other tasks To invoke a Math class method, write: Name of the class (Math) A period Name of the method Any required arguments Object-Oriented Application Development Using VB .NET

Writing Decision-Making Statements Decision-making statements evaluate conditions and execute statements based on that evaluation VB .NET includes: If and Select Case statements If statement: Evaluates an expression Executes one or more statements if expression is true Can execute another statement or group of statements if expression is false Object-Oriented Application Development Using VB .NET

Writing Decision-Making Statements Select Case statement: Evaluates a variable for multiple values Executes a statement or group of statements, depending on contents of the variable being evaluated Object-Oriented Application Development Using VB .NET

Object-Oriented Application Development Using VB .NET Writing If Statements VB .NET If statement interrogates a logical expression that evaluates to true or false An expression often compares two values using logical operators Object-Oriented Application Development Using VB .NET

Object-Oriented Application Development Using VB .NET Writing If Statements Object-Oriented Application Development Using VB .NET

Object-Oriented Application Development Using VB .NET Writing If Statements VB .NET If statement has two forms: Simple If and If-Else Simple If Evaluates an expression Executes one or more statements if expression is true Object-Oriented Application Development Using VB .NET

Object-Oriented Application Development Using VB .NET Writing If Statements Object-Oriented Application Development Using VB .NET

Object-Oriented Application Development Using VB .NET Writing If Statements If-Else Evaluates an expression Executes one or more statements if expression is true Executes a second statement or set of statements if expression is false Object-Oriented Application Development Using VB .NET

Object-Oriented Application Development Using VB .NET Writing If Statements Object-Oriented Application Development Using VB .NET

Writing Select Case Statements Acts like a multiple-way If statement Transfers control to one of several statements, depending on the value of an expression Object-Oriented Application Development Using VB .NET

Object-Oriented Application Development Using VB .NET Writing Loops Loops: repeated execution of one or more statements until a terminating condition occurs Three types of loops: Do While Do Until For Next Object-Oriented Application Development Using VB .NET

Object-Oriented Application Development Using VB .NET Writing Do While Loops Use a Do While to display the numbers 1- 3: ' do while loop ' declare and initialize loop counter variable Dim i As Integer = 1 Do While i <= 3 Console.WriteLine("do while loop: i = " & i) i += 1 Loop Object-Oriented Application Development Using VB .NET

Object-Oriented Application Development Using VB .NET Writing Do While Loops Do While loop continues executing the statement as long as the expression evaluates to true An infinite loop: loop that does not terminate without outside intervention While loop A variation of the Do While loop Functions like the Do While loop Object-Oriented Application Development Using VB .NET

Object-Oriented Application Development Using VB .NET Writing Do Until Loops A Do Until loop: ' do until loop i = 1 ' re-initialize loop counter variable Do Until i > 3 Console.WriteLine("do until loop: i = " & i) i += 1 Loop Object-Oriented Application Development Using VB .NET

Object-Oriented Application Development Using VB .NET Writing Do Until Loops Difference between a Do While and Do Until loop: Do While loop executes while the expression is true Do Until loop executes while the expression is false Object-Oriented Application Development Using VB .NET

Writing Post-Test Loops Programming languages provide two kinds of loops: Pre-test loop tests the terminating condition at the beginning of the loop Post-test loop tests the terminating condition at the end of the loop Object-Oriented Application Development Using VB .NET

Writing Post-Test Loops ' post-test evaluates the expression at end of loop Do Console.WriteLine("post-test executed") i += 1 Loop While i > 3 ' expression initially false Object-Oriented Application Development Using VB .NET

Writing Post-Test Loops Object-Oriented Application Development Using VB .NET

Writing Post-Test Loops Do While and Do Until loops can be written as either pre-test or post-test loops For Next and While loops are always pre-test Object-Oriented Application Development Using VB .NET

Object-Oriented Application Development Using VB .NET Writing For Next Loops VB .NET For Next loop: Includes loop counter initialization and incrementing code as a part of the For statement Uses pre-test logic – it evaluates the terminating expression at the beginning of the loop Example: ' for next loop For i = 1 To 3 Step 1 Console.WriteLine("for next loop: i = " & i) Next Object-Oriented Application Development Using VB .NET

Object-Oriented Application Development Using VB .NET Writing Nested Loops Nested loop: A loop within a loop Can be constructed using any combination of Do While, Do Until, or For Next loops Object-Oriented Application Development Using VB .NET

Declaring and Accessing Arrays Arrays: create a group of variables with the same data type In an array Each element behaves like a variable All elements must have the same data type Elements either can contain primitive data or can be reference variables Object-Oriented Application Development Using VB .NET

Declaring and Accessing Arrays Arrays can be either one-dimensional or multi-dimensional One-dimensional array consists of elements arranged in a row Two-dimensional array has both rows and columns Three-dimensional array has rows, columns, and pages VB .NET implements multi-dimensional arrays as arrays of arrays Object-Oriented Application Development Using VB .NET

Using One-Dimensional Arrays Declare a 5-element array with of integers: ' declare an integer array with 5 elements Dim testScores(4) As Integer Individual array elements are accessed by writing the array reference variable, followed by the index value of the element enclosed in parentheses Object-Oriented Application Development Using VB .NET

Using One-Dimensional Arrays Code to initialize the array elements:  testScores(0) = 75 testScores(1) = 80 testScores(2) = 70 testScores(3) = 85 testScores(4) = 90 An array can be declared and populated using a single statement: Dim testScores() As Integer = {75, 80, 70, 85, 90} Object-Oriented Application Development Using VB .NET

Using One-Dimensional Arrays Object-Oriented Application Development Using VB .NET

Using Multidimensional Arrays Conceptually A two-dimensional array is like a table with rows and columns A three-dimensional array is like a cube, with rows, columns, and pages Each dimension has its own index Declare an Integer array with five rows and two columns Dim testScoreTable(4, 1) As Integer Object-Oriented Application Development Using VB .NET

Using Multidimensional Arrays Code to populate the array: ' populate the elements in column 1 testScoreTable(0, 0) = 75 testScoreTable(1, 0) = 80 testScoreTable(2, 0) = 70 testScoreTable(3, 0) = 85 testScoreTable(4, 0) = 90 ' populate the elements in column 2 testScoreTable(0, 1) = 80 testScoreTable(1, 1) = 90 testScoreTable(2, 1) = 60 testScoreTable(3, 1) = 95 testScoreTable(4, 1) = 100 Object-Oriented Application Development Using VB .NET

Using Multidimensional Arrays Object-Oriented Application Development Using VB .NET

Object-Oriented Application Development Using VB .NET Summary An identifier is the name of a class, method, or variable All variables have a data type, name, and value VB .NET has nine primitive data types VB .NET has two kinds of variables: primitive variables and reference variables Math class has methods to accomplish exponentiation, rounding, etc. VB .NET provides two types of decision-making statements: If statement and Select Case statement Object-Oriented Application Development Using VB .NET

Object-Oriented Application Development Using VB .NET Summary You write VB .NET loops using one of three keywords: Do While, Do Until, or For Next There are two kinds of loops: pre-test loop and post-test loop A nested loop is a loop within a loop A one-dimensional array consists of elements arranged in a single row A two-dimensional array has both rows and columns Object-Oriented Application Development Using VB .NET