Numbers continued The Integer Data Type Multiple Declarations Parentheses Three Types of Errors.

Slides:



Advertisements
Similar presentations
Chapter 3 – Fundamentals of Programming in VB.NET
Advertisements

Operators Same as standard math operators with 2 exceptions –* for multiplication –^ for exponentiation Order of operations strictly observed –Please Excuse.
VB Numbers and Strings School of Business Eastern Illinois University (Week 4, Monday 2/03/2003) © Abdou Illia, Spring 2003.
Input Dialog Box An input dialog box can be used to obtain a single item of input from the user Presents a window (dialog box) requesting input Syntax:
Fundamentals of Programming in Visual Basic
Chapter 31 Fundamentals of Programming in Visual Basic (Continue IV) Strings Variables and Strings Using Text Boxes for Input and Output Concatenation.
Chapter 31 Fundamentals of Programming in VB(Continue I) Numbers Arithmetic Operations Variables Incrementing the Value of a Variable.
Chapter 3: Introducing the Microsoft.NET Framework and Visual Basic.NET Visual Basic.NET Programming: From Problem Analysis to Program Design.
Variables & Math Operators CE 311 K - Introduction to Computer Methods Daene C. McKinney.
Chapter 3 - VB 2008 by Schneider1 Chapter 3 – Variables, Input, and Output 3.1 Numbers 3.2 Strings 3.3 Input and Output.
Chapter 31 Fundamentals of Programming in Visual Basic (Continue VI) String Properties and Methods: "Visual".Length is 6. "Visual".ToUpper is VISUAL. "123.
1 Chapter 3 – Variables, Input, and Output 3.1 Numbers 3.2 Strings 3.3 Input and Output.
Created By Mayson Al-Duwais1. Using Exit to Terminate Repetition Statements To terminate different types of repetition statements you can use a special.
Saving and Loading Simple Text Files A sequential file stores characters one after the other like songs on a cassette tape. New characters are added to.
Input/Output CE 311 K - Introduction to Computer Methods Daene C. McKinney.
CS0004: Introduction to Programming Variables – Numbers.
CS0004: Introduction to Programming Input and Output.
R EVIEW OF C HAPTER 2. H OW TO D EVELOP A VB A PPLICATION Design the Interface for the user Literally draw the GUI Drag buttons/text boxes/etc onto form.
Chapter 3 - VB.NET by Schneider1 Chapter 3 – Fundamentals of Programming in VB.NET VB.NET Controls VB.NET Events Numbers Strings Input and Output.
Chapter 3 - VB 2005 by Schneider1 Chapter 3 – Fundamentals of Programming in Visual Basic 3.1 Visual Basic Controls 3.2 Visual Basic Events 3.3 Numbers.
CS0004: Introduction to Programming Variables – Strings.
1 Chapter 3 – Variables, Input, and Output 3.1 Numbers 3.2 Strings 3.3 Input and Output.
1 Chapter 3 – Variables, Input, and Output 3.1 Numbers 3.2 Strings 3.3 Input and Output.
Chapter 3 - VB 2008 by Schneider1 Chapter 3 – Variables, Input, and Output 3.1 Numbers 3.2 Strings 3.3 Input and Output.
Microsoft Visual Basic 2005 BASICS Lesson 4 Mathematical Operators.
Visual Basic.NET BASICS Lesson 4 Mathematical Operators.
Microsoft Visual Basic 2005 CHAPTER 4 Variables and Arithmetic Operations.
Chapter 4 Variables and constants. 4.1 Variables -Use of variables is good programming style -easier to modify -easier for a programmer to understand.
Visual Basic IITG to be expanded. What is Visual Basic? Object Oriented Programming Language (OOP) Graphical User Interface (GUI) Event Driven – Write.
1 Chapter 3 – Fundamentals of Programming in Visual Basic 3.1 Visual Basic Controls 3.2 Visual Basic Events 3.3 Numbers 3.4 Strings 3.5 Input and Output.
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 3 Variables, Constants, Methods, and Calculations.
Chapter 8 - Visual Basic Schneider
Introduction to Visual Basic Programming. Introduction Simple Program: Printing a Line of Text Another Simple Program: Adding Integers Memory Concepts.
Variables & Function Calls. Overview u Variables  Programmer Defined & Intrinsic  Data Types  Calculation issues u Using Functions  The val() function.
Chapter 51 Logical Operators Used with Boolean expressions Not – makes a False expression True and vice versa And – will yield a True if and only if both.
Chapter 4 Variables and constants. 4.1 Variables -Use of variables is good programming style -easier to modify -easier for a programmer to understand.
Introduction to Programming Fundamentals of Programming in Visual Basic.
1 Chapter 3 – Examples The examples from chapter 3, combining the data types, variables, expressions, assignments, functions and methods with Windows controls.
Hungarian Notation A must in this course Every object used MUST be renamed including the form(s) using the following rules Form  frmFormName E.g. frmTemperature.
Chapter 4 Getting Started with VBA. Subroutines Subroutine is the logical section of code that performs a particular task. Subroutine is also called a.
110 E-1 Variables, Constants and Calculations(2) Chapter 3: Operations on variables, scope of a variable, formatting data Doing Arithmetic.
CS4 –lecture 6 Wednesday, Jan 19, 2011 Roxana Gheorghiu.
Variables and Expressions Programming Right from the Start with Visual Basic.NET 1/e 7.
Microsoft Visual Basic 2012 CHAPTER FOUR Variables and Arithmetic Operations.
Knowledge Base. Defining a Variable Dim statement Dim intXX As Integer Public in a Module Public dblNN As Double.
Chapter 3: Introducing the Microsoft.NET Framework and Visual Basic.NET Visual Basic.NET Programming: From Problem Analysis to Program Design.
3.4 Strings Variables and Strings Using Text Boxes for Input and Output Concatenation ANSI Character Set String Properties and Methods: LengthToUpper TrimToLower.
Chapter 3 - VB 2008 by Schneider1 Chapter 3 – Variables, Input, and Output 3.1 Numbers 3.2 Strings 3.3 Input and Output.
FILES AND EXCEPTIONS Topics Introduction to File Input and Output Using Loops to Process Files Processing Records Exceptions.
Data Types. Visual Basic provides data type Single for storing single-precision floating-point numbers. Data type Double requires more memory to store.
Chapter 3 – Fundamentals of Programming in Visual Basic
Chapter 3 – Variables, Input, and Output
Chapter 3 – Variables, Input, and Output
Variables and Arithmetic Operations
Chapter 3 – Variables, Input, and Output
Fundamentals of Programming in VB.NET
Numbers.
Strings(Part 1) String Literal and String Variable
String Variable, Methods and Properties
Section 3.3 Numbers Arithmetic Operations Variables
Variable Review & IO User 12/26/2018.
Chapter 3.5 Input and Output
Input and Output.
String Variable, Methods and Properties
Additional Topics in VB.NET
String Variable, Methods and Properties
Introduction to Programming
String Variable, Methods and Properties
Input and Output.
Input and Output Chapter 3.5
Presentation transcript:

Numbers continued The Integer Data Type Multiple Declarations Parentheses Three Types of Errors

Arithmetic Operations Numbers are called numeric literals Five arithmetic operations in VB.NET –+ addition –- subtraction –* multiplication –/ division –^ exponentiation

Variables Declaration: Dim speed As Double Variable name Data type Assignment: speed = 50

Initialization Numeric variables are automatically initialized to 0: Dim varName As Double To specify a nonzero initial value Dim varName As Double = 50

Incrementing To add 1 to the numeric variable var var = var + 1 Or as a shortcut var +=1

Multiple Declarations Dim a, b As Double Two other types of multiple-declaration statements are Dim a As Double, b As Integer Dim c As Double = 2, b As Integer = 5

Three Types of Errors Syntax error Run-time error Logic error

3.4 Strings Variables and Strings Using Text Boxes for Input and Output Concatenation ANSI Character Set String Properties and Methods: LengthToUpper TrimToLower IndexOfSubstring

Strings continued The Empty String Initial Value of a String Option Strict Internal Documentation Line-Continuation Character

Variables and Strings Private Sub btnDisplay_Click(...) Handles btnDisplay.Click Dim today As String today = "Monday" With lstOutput.Items.Clear().Add("hello").Add(today) End With End Sub

Using Text Boxes for Input and Output The contents of a text box is always a string Input example strVar = txtBox.Text Output example txtBox.Text = strVar

Data Conversion Because the contents of a text box is always a string, sometimes you must convert the input or output numVar = CDbl(txtBox.Text) txtBox.Text = CStr(numVar) Converts a String to a Double Converts a number to a string

Concatenation Combining two strings to make a new string quote1 = "The ballgame isn't over, " quote2 = "until it's over." quote = quote1 & quote2 txtOutput.Text = quote & " Yogi Berra" Displays The ball game isn't over until it's over. Yogi Berra

ANSI Character Set A numeric representation for every key on the keyboard

String Properties and Methods: "Visual".Length is 6. "Visual".ToUpper is VISUAL. "123 Hike".Length is 8. "123 Hike".ToLower is 123 hike. "a" & " bcd ".Trim & "efg" is abcdefg.

More String Properties and Methods: "fanatic".Substring(0, 3) is "fan". "fanatic".IndexOf("ati") is 3. "fanatic".Substring(4, 2) is "ti". "fanatic".IndexOf("a") is 1. "fanatic".Substring(4) is "tic". "fanatic".IndexOf("nt") is –1.

The Empty String The string "", which contains no characters, is called the empty string or the zero-length string. The statement lstBox.Items.Add("") skips a line in the list box. The contents of a text box can be cleared with either the statement txtBox.Clear() or the statement txtBox.Text = ""

Initial Value of a String By default the initial value is Nothing Strings can be given a different initial value as follows: Dim today As String = "Monday"

Option Strict VB.NET allows numeric variables to be assigned strings and vice versa, a poor programming practice. To turn this feature off, put the following statement at the very top of the code window Option Strict On

Internal Documentation 1.Other people can easily understand the program. 2.You can understand the program when you read it later. 3.Long programs are easier to read because the purposes of individual pieces can be determined at a glance.

Line-Continuation Character A long line of code can be continued on another line by using underscore (_) preceded by a space msg = "640K ought to be enough " & _ "for anybody. (Bill Gates, 1981)"

3.5 Input and Output Formatting Output with Format Functions Formatting Output with Zones Reading Data from Files Getting Input from an Input Dialog Box Using a Message Dialog Box for Output

Formatting Output with Format Functions FunctionString Value FormatNumber( ,1)12,345.6 FormatCurrency( ,2)$12, FormatPercent(0.185,2)18.50%

Formatting Output with Zones Use a fixed-width font such as Courier New Divide the characters into zones with a format string. Dim fmtStr As String = "{0, 15}{1, 10}{2, 8}" lstOutput.Items.Add(String.Format(fmtStr, data0, data1, data2))

Inputting Data Data can be stored in files and accessed with a StreamReader object or supplied by the user with an input dialog box.

Steps to Use StreamReader 1.Execute a statement of the form Dim readerVar As IO.StreamReader = _ IO.File.OpenText(filespec) or the pair of statements Dim readerVar As IO.StreamReader readerVar = IO.File.OpenText(filespec) 2.Assume the file contains one item of data per line. Read items of data in order, one at a time, from the file with the ReadLine method. strVar = readerVar.ReadLine 3.After the desired items have been read from the file, terminate the communications link readerVar.Close()

Getting Input from an Input Dialog Box stringVar = InputBox(prompt, title) fileName = InputBox("Enter the name " _ & "of the file containing the " & _ "information.", "Name of File")

Using a Message Dialog Box for Output MsgBox(prompt,, title) MsgBox("Nice try, but no cigar.",, "Consolation")