Data Types 1.

Slides:



Advertisements
Similar presentations
Ch. 3 Variables VB.Net Programming. Data Types Boolean – True or False values Short – Small integers (+/- 32,767) Integer – Medium-size integers (+/-
Advertisements

Operators & Identifiers The Data Elements. Arithmetic Operators exponentiation multiplication division ( real ) division ( integer quotient ) division.
L2:CSC © Dr. Basheer M. Nasef Lecture #2 By Dr. Basheer M. Nasef.
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
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.
CIS 234: Using Data in Java Thanks to Dr. Ralph D. Westfall.
Chapter 3.3 Numeric Data Types and Variables. Slide 2 Objectives Create variables to store information while a solution runs Perform computations with.
The number of calories burned per hour by cycling, jogging and swimming are 200, 475 and 275 respectively. A person loses 1pound of weight for each 3500.
Data types and variables
IS437: Fall 2004 Instructor: Dr. Boris Jukic Data Types, Constants, Variables, Scope, Conversion.
Chapter 2 Data Types, Declarations, and Displays
JavaScript, Third Edition
CSci 142 Data and Expressions. 2  Topics  Strings  Primitive data types  Using variables and constants  Expressions and operator precedence  Data.
VB DATATYPES, VARIABLES, CONSTANTS & CALCULATIONS.
1 Chapter Two Using Data. 2 Objectives Learn about variable types and how to declare variables Learn how to display variable values Learn about the integral.
Chapter 4 Introduction to Numeric Data Types and Variables.
Objectives You should be able to describe: Data Types
Dani Vainstein1 VBScript Session 9. Dani Vainstein2 What we learn last session? VBScript coding conventions. Code convention usage for constants, variables,
© 2006 ITT Educational Services Inc. Introduction to Computer Programming: Unit 2: Chapter 3: Slide 1 Unit 2 Variables and Calculations Chapter 3 Input,
Java Primitives The Smallest Building Blocks of the Language (corresponds with Chapter 2)
Variable, Expressions, Statements and Operators By: Engr. Faisal ur Rehman CE-105 Fall 2007.
Chapter 2 Basic Elements of Java. Chapter Objectives Become familiar with the basic components of a Java program, including methods, special symbols,
1 Do you have a CS account? Primitive types –“ building blocks ” for more complicated types Java is strongly typed –All variables in a Java program must.
CH2 – Using Data. Constant Something which cannot be changed Data Type Format and size of a data item Intrinsic Data Types Pg. 47 – Table 2-1 Basic ones.
Chapter 2: Using Data.
3 - Variables Lingma Acheson Department of Computer and Information Science, IUPUI CSCI N331 VB.NET Programming.
Computer Programming TCP1224 Chapter 4 Variables, Constants, and Arithmetic Operators.
Data & Data Types & Simple Math Operation 1 Data and Data Type Standard I/O Simple Math operation.
Java Programming: From Problem Analysis to Program Design, 4e Chapter 2 Basic Elements of Java.
Course Title: Object Oriented Programming with C++ instructor ADEEL ANJUM Chapter No: 03 Conditional statement 1 BY ADEEL ANJUM (MSc-cs, CCNA,WEB DEVELOPER)
Operators & Identifiers The Data Elements. Arithmetic Operators exponentiation multiplication division ( real ) division ( integer quotient ) division.
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 3 Variables, Constants, Methods, and Calculations.
Data Types Declarations Expressions Data storage C++ Basics.
CSCI 3133 Programming with C Instructor: Bindra Shrestha University of Houston – Clear Lake.
Microsoft Visual Basic 2010: Reloaded Fourth Edition Chapter Three Memory Locations and Calculations.
Java Programming, Second Edition Chapter Two Using Data Within a Program.
COMP Primitive and Class Types Yi Hong May 14, 2015.
Data Tonga Institute of Higher Education. Variables Programs need to remember values.  Example: A program that keeps track of sales needs to remember.
Variables in VB.NET. Variables  A storage location in memory (RAM)  Holds data/information while the program is running  These storage locations can.
 Variables can store data of different types, and different data types can do different things.  PHP supports the following data types:  String  Integer.
Variables and Expressions Programming Right from the Start with Visual Basic.NET 1/e 7.
DATA TYPES, VARIABLES AND CONSTANTS. LEARNING OBJECTIVES  Be able to identify and explain the difference between data and information  Be able to identify,
CIS 338: VB Variables Dr. Ralph D. Westfall April, 2011.
Making Interactive Programs with Visual Basic .NET
© 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.
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.
Data Types. Visual Basic provides data type Single for storing single-precision floating-point numbers. Data type Double requires more memory to store.
Chapter 2 Variables and Constants. Objectives Explain the different integer variable types used in C++. Declare, name, and initialize variables. Use character.
Introduction to Programming Lecture 3 Msury Mahunnah, Department of Informatics, Tallinn University of Technology.
IS 350 Numeric Data Types.
Egyptian Language School Computer Department
A variable is a name for a value stored in memory.
Chapter 2 Variables.
Arithmetic operations and operators, converting data types and formatting programs for output. Year 11 Information Technology.
An Application Uses Variables to Hold Information So It May Be Manipulated, Used to Manipulate Other Information, or Remembered for Later Use.
BASIC ELEMENTS OF A COMPUTER PROGRAM
Data Types, Arithmetic Operations
Data Types 1.
Type Conversion, Constants, and the String Object
Lecture Set 4 Data Types and Variables
Chapter 2.
Introduction to Tools, Numeric Data Types and Variables
Numbers.
Chapter 2 Variables.
C++ Data Types Data Type
Chapter 2 Variables.
DATA TYPES AND OPERATIONS
C Programming Lecture-3 Keywords, Datatypes, Constants & Variables
Presentation transcript:

Data Types 1

Single or Double ? Visual Basic provides data type Single for storing single-precision floating-point numbers. Data type Double requires more memory to store a floating-point value, but is more accurate than type Single. Type Single is useful in applications that need to conserve memory and do not require the accuracy provided by type Double.

Dim statement declares variable Dim varname As type [ = initexpr ] Declaring a Variable Dim statement declares variable Dim varname As type [ = initexpr ] varname is variable name As type contains data type of variable Optional initexpr contains the initial value of a variable

Initialize a variable when declaring it Declaring a Variable Initialize a variable when declaring it New to VB .NET Declare an Integer variable and store the value 30 in the variable Dim mintYearTerm As Integer = 30

Declaring a Variable Possible to declare multiple variables on the same line Dim mintYearTerm, mintMonthTerm As Integer

Declaring Constants Declare constants with the Const statement. Constants are similar to variables – constants are values that are stored to memory locations; however, a constant cannot have its value change during program execution – constant values are generally fixed over time. Examples: Const SALES_TAX_RATE_SINGLE As Single = 0.0725F Const BIG_STATE_NAME_STRING As String = "Alaska" Const TITLE_STRING As String = "Data Entry Error" Const MAX_SIZE_INTEGER As Integer = 4000

Declaring Constants Follow these rules for assigning numeric values to constants: You can use numbers, a decimal point, and a plus (+) or minus (-) sign. Do not include special characters such as a comma, dollar sign, or other special characters. Append one of these characters to the end of the numeric constant or variable to denote a data type declaration. If you do not use these, a whole number is assumed to be Integer and a fractional value is assumed to be Double. Decimal D 40.45D Double R 12576.877R Integer I 47852I Long L 9888444222L Short S 2588S Single F 0.0725F

Strings Such as sentences, words, letters of the alphabet, names, telephone numbers& addresses. A string constant is a sequence of characters that is treated as a single item.

Strings quote1 = “ The ball game isn’t over “ quote2 = “ until it is over “ quote = quote1 & “ , “ & quote2 Console.WriteLine ( quote )  The ball game isn’t over , until it is over

Examining Variable Types IsNumeric() IsDate() System.Date.IsLeapYear (2001)  False

Boolean Data Type It stores True (1) / False (0) Any non-zero value will be considered as TRUE. These variables are combined with the logical operators.. AND, OR & NOT.

Converting Input Data Types Text property always stores string values, even if the string looks like a number. Parse method – converts a string value to an equivalent numeric value for storage to a numeric variable. Parse means to examine a string character by character and convert the value to another format such as decimal, integer, or string. Dim QuantityInteger As Integer = Integer.Parse(TextBox2.Text)

Conversion Between Data Types 1. Methods belong to the System.Convert class ToInt16 converts value to a Short ToInt32 converts value to an Integer ToInt64 converts value to a Long ToDouble converts value to a Double ToSingle converts value to a Single ToString converts value to a String

Conversion Between Data Types Dim msngInput As Single = 3.44 Dim mstrInput As String = "3.95" Dim mintOutput As Integer Dim msngOutput As Single Convert a Single to an Integer mintOutput = System.Convert.ToInt32(msngInput) Convert a String to an Integer mintOutput = System.Convert.ToInt32(mstrInput) Convert a String to a Single msngOutput = System.Convert.ToSingle(mstrInput)

Conversion Between Data Types 2. CType and named functions: CType method Dim A As string = “34.56” Dim B As Double B = CType ( A , Double) / 1.14 Older versions of VB used named functions to convert values. Examples are the CDec (convert to Decimal) and CInt (convert to Integer): PriceDecimal = CDec(TextBox1.Text) QuantityInteger = CInt(TextBox2.Text) CDate, CDec, CStr, CLng, CChar, CBool, CByte

Implicit Conversion Implicit Conversion – this is conversion by VB from a narrower to wider data type (less memory to more memory) – this is done automatically as there is no danger of losing any precision. In this example, an integer (4 bytes) is converted to a double (8 bytes): BiggerNumberDouble = SmallerNumberInteger