Object Oriented Programming with Visual Basic.Net

Similar documents
I101/B100 Problem Solving with Computers

CS313D: ADVANCED PROGRAMMING LANGUAGE

I101/B100 Problem Solving with Computers

Microsoft Visual Basic 2015: Reloaded

Computers and Programming Section 450. Lab #1 C# Basic. Student ID Name Signature

Visual C# Instructor s Manual Table of Contents

Introduction to C# Applications

Microsoft Visual Basic 2005: Reloaded

Objectives. Introduce the core C# language features class Main types variables basic input and output operators arrays control constructs comments

Programming Language 2 (PL2)

Introduction To C#.NET

Darshan Institute of Engineering & Technology for Diploma Studies

Agenda & Reading. VB.NET Programming. Data Types. COMPSCI 280 S1 Applications Programming. Programming Fundamentals

Outline. Data and Operations. Data Types. Integral Types

Chapter 2: Using Data

CS112 Lecture: Primitive Types, Operators, Strings

Introduction to Visual Basic and Visual C++ Arithmetic Expression. Arithmetic Expression. Using Arithmetic Expression. Lesson 4.

C# Fundamentals. built in data types. built in data types. C# is a strongly typed language

I101/B100 Problem Solving with Computers

C++ Programming: From Problem Analysis to Program Design, Third Edition

Chapter 2.4: Common facilities of procedural languages

Chapter 2: Using Data

Fig 1.1.NET Framework Architecture Block Diagram

Chapter-8 DATA TYPES. Introduction. Variable:

Chapter 2 Using Data. Instructor s Manual Table of Contents. At a Glance. Overview. Objectives. Teaching Tips. Quick Quizzes. Class Discussion Topics

IT 374 C# and Applications/ IT695 C# Data Structures

Computer Components. Software{ User Programs. Operating System. Hardware

A201 Object Oriented Programming with Visual Basic.Net

SKILL AREA 306: DEVELOP AND IMPLEMENT COMPUTER PROGRAMS

Expressions and Casting. Data Manipulation. Simple Program 11/5/2013

Introduction to Data Entry and Data Types

Full file at

Expressions and Casting

3. Java - Language Constructs I

CHAPTER 3: CORE PROGRAMMING ELEMENTS

CSc 10200! Introduction to Computing. Lecture 2-3 Edgardo Molina Fall 2013 City College of New York

Data and Variables. Data Types Expressions. String Concatenation Variables Declaration Assignment Shorthand operators. Operators Precedence

C++ Basic Elements of COMPUTER PROGRAMMING. Special symbols include: Word symbols. Objectives. Programming. Symbols. Symbols.

Part 4 - Procedures and Functions

VARIABLES. 1. STRINGS Data with letters and/or characters 2. INTEGERS Numbers without decimals 3. FLOATING POINT NUMBERS Numbers with decimals

Reserved Words and Identifiers

[0569] p 0318 garbage

Full file at

BASIC ELEMENTS OF A COMPUTER PROGRAM

UNIT- 3 Introduction to C++

Ex: If you use a program to record sales, you will want to remember data:

9/5/2018. Overview. The C Programming Language. Transitioning to C from Python. Why C? Hello, world! Programming in C

Lecture 3 Tao Wang 1

VB CONSOLE SUMMER WORK. Introduction into A Level Programming

Chapter 2 Using Data. Instructor s Manual Table of Contents. At a Glance. A Guide to this Instructor s Manual:

The C Programming Language. (with material from Dr. Bin Ren, William & Mary Computer Science)

VARIABLES AND TYPES CITS1001

Introduction to Programming Using Java (98-388)

Midterms Save the Dates!

Overview About KBasic

variables programming statements

CS242 COMPUTER PROGRAMMING

Chapter 1 Getting Started

Types and Expressions. Chapter 3

An overview about DroidBasic For Android

Zheng-Liang Lu Java Programming 45 / 79

By the end of this section you should: Understand what the variables are and why they are used. Use C++ built in data types to create program

A201 Object Oriented Programming with Visual Basic.Net

Data Types. Strings Variables Declaration Statements Named Constant Assignment Statements Intrinsic (Built-in) Functions

Lesson 3: Basic Programming Concepts

An Introduction to Processing

CEN 414 Java Programming

Fundamentals of Programming CS-110. Lecture 2

Review: Exam 1. Your First C++ Program. Declaration Statements. Tells the compiler. Examples of declaration statements

Unit 6 - Software Design and Development LESSON 4 DATA TYPES

Learning the Language - V

CS5000: Foundations of Programming. Mingon Kang, PhD Computer Science, Kennesaw State University

3. Java - Language Constructs I

Data and Operations. Outline

Question And Answer.

LESSON 2 VARIABLES, OPERATORS, EXPRESSIONS, AND USER INPUT

VB FUNCTIONS AND OPERATORS

Homework #3 CS2255 Fall 2012

Chapter 2 Working with Data Types and Operators

Python for Analytics. Python Fundamentals RSI Chapters 1 and 2

Values, Variables, Types & Arithmetic Expressions. Agenda

CSCI 2010 Principles of Computer Science. Data and Expressions 08/09/2013 CSCI

Vba Variables Constant and Data types in Excel

COMS 469: Interactive Media II

Computer Programming C++ (wg) CCOs

Objectives. Chapter 2: Basic Elements of C++ Introduction. Objectives (cont d.) A C++ Program (cont d.) A C++ Program

Expressions. Arithmetic expressions. Logical expressions. Assignment expression. n Variables and constants linked with operators

Chapter 2: Basic Elements of C++

Chapter 2: Basic Elements of C++ Objectives. Objectives (cont d.) A C++ Program. Introduction

A variable is a name for a location in memory A variable must be declared

Introduction. Following are the types of operators: Unary requires a single operand Binary requires two operands Ternary requires three operands

Unit 4. Lesson 4.1. Managing Data. Data types. Introduction. Data type. Visual Basic 2008 Data types

! A program is a set of instructions that the. ! It must be translated. ! Variable: portion of memory that stores a value. char

Chapter 1 & 2 Introduction to C Language

Data and Expressions. Outline. Data and Expressions 12/18/2010. Let's explore some other fundamental programming concepts. Chapter 2 focuses on:

Module 2 - Part 2 DATA TYPES AND EXPRESSIONS 1/15/19 CSE 1321 MODULE 2 1

Basics of Java Programming

Fundamentals. Fundamentals. Fundamentals. We build up instructions from three types of materials

BEGINNING PROBLEM-SOLVING CONCEPTS FOR THE COMPUTER. Chapter 2

Introduction to. Copyright HKTA Tang Hin Memorial Secondary School 2016

Transcription:

Object Oriented Programming with Visual Basic.Net By: Dr. Hossein Hakimzadeh Computer Science and Informatics IU South Bend (c) Copyright 2007 to 2015 H. Hakimzadeh 1

What do we need to learn in order to write computer programs? Fundamental programming constructs: Variables, Arithmetic operators, Input and output Conditions, Loops, Procedures and functions, Arrays, Structures, classes and objects, Files 2

Variables: Remember this figure. Variables in VB are the method by which programmers can access and manipulate memory. Input Storage Computer CPU Arithmetic Logic Unit Control Unit Memory Output Communication 3

Variables A variable is the name given to a memory location. (the memory location may hold data items such as numbers, characters, etc.) VB programs store and manipulate their data by using variables. Syntax: Dim variable_name AS data_type Example: Declaring Variables: Dim x As Integer Dim y As Double Dim z As char Using the Variables: x = 5 y = 4.8 z = A' 4

Assignment Statement Syntax: variable = expression = is the assignment operator An expression is a combination of variables, constants, numbers and operators. Examples: N1 = N2 variable = variable N1 = 5 variable = constant number N1 = N2 * 5 +1 variable = expression N1 = N1 + 5 5

Data Types In VB, each variable must have a data type. VB provides a number of built-in data types. These include: Type Size Description Integer 4 bytes integer Double 8 bytes floating point or real number Decimal 12 bytes Similar to float but more exact Long 8 bytes Long integer (64 bit integer) Char 2 bytes Unicode character Byte 1 byte 0 to 255 Boolean 1 byte True or False Date 8 bytes holds time and date String variable holds variable sized strings 6

Declaring a Variable In most modern programming languages variables must be declared before they are used. Examples of variable declaration in VB: Dim X As Integer Variable name data type 7

Declaring a variable will accomplish the following: 1) Associate the variable name with some memory location in which the data will be stored. 2) Tell the compiler how much memory is needed for each variable: x y c ===> 4 bytes ===> 8 bytes ===> 2 bytes Dim X As Integer Dim Y As Double Dim C As Char 3) Allow the compiler to perform type compatibility checking. For example the compiler can easily identify problems like: c = 5.8; y = hello compiler error (c is a character not a floating point number) compiler error (Y is double not a string) 8

Type Checking Traditionally the BASIC language was not a strongly typed language. However, in VB.Net the programmer can explicitly tell the compiler to enforce strong type checking. Strong type checking can be enforced with the help of the following two statements. Option Strict On 'Tells the compiler to enforce strict type checking. Option Explicit On 'Tells the compiler that variables must be declared before use. 9

Type Compatibility The numbers 10 and 10.0 are not the same and therefore, have different types: 10 is an integer number. 10.0 is a floating point number. The compiler will automatically convert an integer number to its equivalent float number however, the reverse is not true. Example: Dim x as double x =10 Will automatically convert to a float Dim y as integer y = 10.5 Error or warning in most compilers 10

Arithmetic Operators: Remember this figure. Arithmetic operators are implemented in the Arithmetic Logic Unit of the computer. Input Storage Computer CPU Arithmetic Logic Unit Control Unit Memory Output Communication 11

Arithmetic Operators + Addition - Subtraction * Multiplication / Real division \ Integer division MOD Remainder of an integer division (modula) Example: 5.0 / 2.0 ==> 2.5 5 \ 2 ==> 2 4 / 2 ==> 2 5 MOD 2 ==> 1 12

Arithmetic Operators Module Module1 Sub Main() Dim x, y As Integer x = 5 y = 2 Console.WriteLine(x / y) ' output = 2.5 Console.WriteLine(x \ y) ' output = 2 Console.WriteLine(x Mod y) ' output = 1 Console.WriteLine(y Mod x) ' output = 2 Dim a, b As Double a = 5.0 b = 2.0 Console.WriteLine(a / b) ' output = 2.5 Console.ReadLine() ' Pause! End Sub End Module 13

Input and Output Input Computer CPU Arithmetic Logic Unit Output I/O is an essential part of any application. Control Unit Memory Storage Communication 14

Output (Console Applications) Output can be sent to the computer display by using the Write() or WriteLine() procedures. Syntax: System.Console.WriteLine(argument) Arguments can be: constant (string or numeric) or variable 15

Output (Console Applications) Example 1: Option Strict On Option Explicit On Module Module1 Sub Main() End Sub End Module 3 15 HELLO System.Console.WriteLine(3) System.Console.WriteLine(3 * 5) System.Console.WriteLine("HELLO") 16

Output (Console Applications) Example 2: Option Strict On Option Explicit On Module Module1 Sub Main() Dim temp As Integer = 75 Console.WriteLine("The temperature is {0} degrees", temp) Dim A, B As Integer A = 10 B = 20 Console.WriteLine("A is = {0} and B is = {1}", A, B) End Sub End Module The temperature is 75 degrees A is = 10 and B is = 20 17

Input (Console Applications) Input can be read from the keyboard by using the ReadLine() function. Syntax: Variable = Console.ReadLine() Note that ReadLine() will return a STRING as the result. So, if a value other than a string is desired the programmer must perform the conversion. 18

Input (Console Applications) Option Strict On Option Explicit On Module Module1 Sub Main() Dim Name As String Console.Write("What is your name? ") Name = Console.ReadLine() Console.WriteLine("Good day {0}.", Name) Dim Age As Double Console.Write("How old are you? ") Age = CDbl(Console.ReadLine()) Console.WriteLine("{0} you are approximately {1} days old.", Name, Age * 365) Console.ReadLine() Pause End Sub End Module 19

Output (Windows Applications) Displays a message box that can contain text, buttons, and symbols that inform and instruct the user. MessageBox.Show("Hello") MessageBox.Show("Hello", "Dialog Box Caption", MessageBoxButtons.OK, MessageBoxIcon.Exclamation) 20

Input (Windows Applications) Displays a prompt in a dialog box, waits for the user to input text or click a button, and then returns a string containing the contents of the text box. Dim strname As String strname = InputBox("What is your name?", "Name") MessageBox.Show(strName) 21

Reminder: Errors Encountered by Programmers Syntax Errors: When VB s rules for punctuation, format, or spelling is violated. Most Syntax errors are detected by the editor in the IDE. Runtime Errors If your program halts or crashes during execution. Example: Divide by zero. Finding the square root of a negative number. Trying to read from a non-existing file. Runtime errors are also known as EXCEPTIONS Logic Errors The program runs but produces incorrect results. 22