VB.NET Programming Fundamentals



Similar documents
Name: Class: Date: 9. The compiler ignores all comments they are there strictly for the convenience of anyone reading the program.

Moving from C++ to VBA

Introduction to Java

Computer Programming I

Handout 1. Introduction to Java programming language. Java primitive types and operations. Reading keyboard Input using class Scanner.

In this Chapter you ll learn:

#820 Computer Programming 1A

Visual Logic Instructions and Assignments

Example of a Java program

Embedded Systems. Review of ANSI C Topics. A Review of ANSI C and Considerations for Embedded C Programming. Basic features of C

Java Basics: Data Types, Variables, and Loops

What is a Loop? Pretest Loops in C++ Types of Loop Testing. Count-controlled loops. Loops can be...

Informatica e Sistemi in Tempo Reale

WESTMORELAND COUNTY PUBLIC SCHOOLS Integrated Instructional Pacing Guide and Checklist Computer Math

AP Computer Science Java Subset

CS 141: Introduction to (Java) Programming: Exam 1 Jenny Orr Willamette University Fall 2013

Pseudo code Tutorial and Exercises Teacher s Version

5 Arrays and Pointers

Perl in a nutshell. First CGI Script and Perl. Creating a Link to a Script. print Function. Parsing Data 4/27/2009. First CGI Script and Perl

Moving from CS 61A Scheme to CS 61B Java

JavaScript: Control Statements I

Answers to Review Questions Chapter 7

We will learn the Python programming language. Why? Because it is easy to learn and many people write programs in Python so we can share.

Object Oriented Software Design

One Dimension Array: Declaring a fixed-array, if array-name is the name of an array

Topics. Parts of a Java Program. Topics (2) CS 146. Introduction To Computers And Java Chapter Objectives To understand:

Fundamentals of Programming and Software Development Lesson Objectives

River Dell Regional School District. Computer Programming with Python Curriculum

PART-A Questions. 2. How does an enumerated statement differ from a typedef statement?

Introduction to Java Applications Pearson Education, Inc. All rights reserved.

Functional Programming

Visual Basic Programming. An Introduction

The C Programming Language course syllabus associate level

JAVA - QUICK GUIDE. Java SE is freely available from the link Download Java. So you download a version based on your operating system.

PL / SQL Basics. Chapter 3

Final Exam Review: VBA

ARIZONA CTE CAREER PREPARATION STANDARDS & MEASUREMENT CRITERIA SOFTWARE DEVELOPMENT,

Introduction to Visual C++.NET Programming. Using.NET Environment

OpenOffice.org 3.2 BASIC Guide

Sources: On the Web: Slides will be available on:

Boolean Expressions, Conditions, Loops, and Enumerations. Precedence Rules (from highest to lowest priority)

CSE 1223: Introduction to Computer Programming in Java Chapter 2 Java Fundamentals

VISUAL GUIDE to. RX Scripting. for Roulette Xtreme - System Designer 2.0

High-Level Programming Languages. Nell Dale & John Lewis (adaptation by Michael Goldwasser)

JavaScript: Introduction to Scripting Pearson Education, Inc. All rights reserved.

TECHNOLOGY Computer Programming II Grade: 9-12 Standard 2: Technology and Society Interaction

Exercise 4 Learning Python language fundamentals

Java (12 Weeks) Introduction to Java Programming Language

Using Casio Graphics Calculators

Introduction to Java. CS 3: Computer Programming in Java

Java Application Developer Certificate Program Competencies

Debugging. Common Semantic Errors ESE112. Java Library. It is highly unlikely that you will write code that will work on the first go

I PUC - Computer Science. Practical s Syllabus. Contents

Keywords are identifiers having predefined meanings in C programming language. The list of keywords used in standard C are : unsigned void

Lecture 2 Notes: Flow of Control

Variables, Constants, and Data Types

Arrays. number: Motivation. Prof. Stewart Weiss. Software Design Lecture Notes Arrays

The Little Man Computer

13 Classes & Objects with Constructors/Destructors

Instruction Set Architecture (ISA)

Introduction to Python

Object Oriented Software Design

MICROSOFT EXCEL FORMULAS

PROGRAMMING IN C PROGRAMMING IN C CONTENT AT A GLANCE

Software development and programming. Software

Chapter 2 Introduction to Java programming

INFORMATION BROCHURE Certificate Course in Web Design Using PHP/MySQL

Writing Control Structures

Excel: Introduction to Formulas

Lecture 5: Java Fundamentals III

Object-Oriented Design Lecture 4 CSU 370 Fall 2007 (Pucella) Tuesday, Sep 18, 2007

Thomas Jefferson High School for Science and Technology Program of Studies Foundations of Computer Science. Unit of Study / Textbook Correlation

First Java Programs. V. Paúl Pauca. CSC 111D Fall, Department of Computer Science Wake Forest University. Introduction to Computer Science

PROBLEM SOLVING SEVENTH EDITION WALTER SAVITCH UNIVERSITY OF CALIFORNIA, SAN DIEGO CONTRIBUTOR KENRICK MOCK UNIVERSITY OF ALASKA, ANCHORAGE PEARSON

Fundamentals of Java Programming

Visual Basic 2010 Essentials

Chapter 5 Functions. Introducing Functions

2. Capitalize initial keyword In the example above, READ and WRITE are in caps. There are just a few keywords we will use:

CSC 221: Computer Programming I. Fall 2011

Introduction. Why (GIS) Programming? Streamline routine/repetitive procedures Implement new algorithms Customize user applications

Two-way selection. Branching and Looping

National Database System (NDS-32) Macro Programming Standards For Microsoft Word Annex - 8

Java Interview Questions and Answers

Addition Methods. Methods Jottings Expanded Compact Examples = 15

C Programming. for Embedded Microcontrollers. Warwick A. Smith. Postbus 11. Elektor International Media BV. 6114ZG Susteren The Netherlands

3.GETTING STARTED WITH ORACLE8i

1.3 Conditionals and Loops

Conditions & Boolean Expressions

Computer Programming I

Programming Database lectures for mathema

Chapter 2: Elements of Java

Changing the Display Frequency During Scanning Within an ImageControls 3 Application

Translating to Java. Translation. Input. Many Level Translations. read, get, input, ask, request. Requirements Design Algorithm Java Machine Language

1 Description of The Simpletron

Information and Computer Science Department ICS 324 Database Systems Lab#11 SQL-Basic Query

Basic Programming and PC Skills: Basic Programming and PC Skills:

QUIZ-II QUIZ-II. Chapter 5: Control Structures II (Repetition) Objectives. Objectives (cont d.) 20/11/2015. EEE 117 Computer Programming Fall

Transcription:

Chapter 3 Objectives Programming Fundamentals In this chapter, you will: Learn about the programming language Write a module definition Use variables and data types Compute with Write decision-making statements Write loops Declare and access arrays 1 2 Introducing Introducing : 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 By adopting the OO model, encourages good software design Good software design can reduce: Debugging chores Maintenance chores 3 4 Writing a Module Definition Writing a Module Definition 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 The statements consist of keywords and identifiers Keywords have special meanings to identifiers are the names assigned by the programmer to modules, procedures, and variables, etc. identifiers: Can be of any length Can include any letter or number, but no spaces Must begin with a letter of the alphabet 5 6

Writing a Module Definition Writing a Module Definition code is not case sensitive 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 (') Procedures begin with a procedure header, which identifies the procedure and describes some of its characteristics has two types of procedures: Function and Sub A Function procedure can return a value A Sub procedure cannot return a value 7 8 Writing a Module Definition Using VB. NET Variables and Data Types 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 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 9 10 Declaring and Initializing Variables Declaring and Initializing Variables Before declaring a variable, the programmer must specify its data type 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 To declare a variable, write: Keyword Dim Name to be used for identifier Keyword As Data type Example: ' declare a variable Dim i As Integer 11 12

Declaring and Initializing Variables 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 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 13 14 Changing Data Types 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, compiler displays an error message With Option Explicit On, the programmer must define a variable before using it in a statement Option Explicit is generally set to On 15 16 Using Constants Using Reference Variables 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 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 17 18

Using Reference Variables Computing with 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 19 20 Computing with Writing Decision-Making Statements 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 Decision-making statements evaluate conditions and execute statements based on that evaluation 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 21 22 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 If statement interrogates a logical expression that evaluates to true or false An expression often compares two values using logical operators 23 24

If statement has two forms: Simple If and If-Else Simple If Evaluates an expression Executes one or more statements if expression is true 25 26 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 27 28 Writing Select Case Statements Select Case statement Acts like a multiple-way If statement Transfers control to one of several statements, depending on the value of an expression 29 30

Writing Loops Writing Do While Loops Loops: repeated execution of one or more statements until a terminating condition occurs Three types of loops: Do While Do Until For Next 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 31 32 Writing Do While Loops Writing Do Until 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 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 33 34 Writing Do Until Loops Writing Post-Test Loops Difference between a Do While and Do Until loop: Do While loop executes while the expression is true Do Until loop executes until the expression is false 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 35 36

Writing Post-Test Loops 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 37 38 Writing For Next Loops Writing Nested Loops 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 Nested loop: A loop within a loop Can be constructed using any combination of Do While, Do Until, or For Next loops 39 40 Declaring and Accessing Arrays 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 Arrays can be either one-dimensional or multidimensional 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 implements multi-dimensional arrays as arrays of arrays 41 42

Using One-Dimensional Arrays 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 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} 43 44 Using One-Dimensional Arrays 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 45 46 Using Multidimensional Arrays 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 47 48

Summary Summary An identifier is the name of a class, method, or variable All variables have a data type, name, and value has nine primitive data types has two kinds of variables: primitive variables and reference variables Math class has methods to accomplish exponentiation, rounding, etc. provides two types of decision-making statements: If statement and Select Case statement You write 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 49 50