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.

Slides:



Advertisements
Similar presentations
Variables in C Amir Haider Lecturer.
Advertisements

 Variables  What are they?  Declaring and initializing variables  Common uses for variables  Variables you get “for free” in Processing ▪ Aka: Built-in.
Lecture Set 4 Data Types and Variables Part B – Variables, Constants, Expressions Conversion Rules Options Strict, Option Explicit Scope of Definition.
Introduction to Computing Concepts Note Set 7. Overview Variables Data Types Basic Arithmetic Expressions ▫ Arithmetic.
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.
CIS 234: Using Data in Java Thanks to Dr. Ralph D. Westfall.
C-1 University of Washington Computer Programming I Lecture 3: Variables, Values, and Types © 2000 UW CSE.
Chapter 3: Introducing the Microsoft.NET Framework and Visual Basic.NET Visual Basic.NET Programming: From Problem Analysis to Program Design.
JavaScript, Third Edition
VB .NET Programming Fundamentals
String Escape Sequences
Basic Elements of C++ Chapter 2.
Identifiers and Assignment Statements. Data structures In any programming language you need to refer to data The simplest way is with the actual data.
Variables, Constants, Methods, and Calculations Chapter 3 - Review.
Programming.
National Diploma Unit 4 Introduction to Software Development Data types, variables and constants.
CPS120: Introduction to Computer Science Variables and Constants Lecture 8 - B.
Java Data Types Data types, variable declaration, and initialization.
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.
CPS120: Introduction to Computer Science
DHTML AND JAVASCRIPT Genetic Computer School LESSON 5 INTRODUCTION JAVASCRIPT G H E F.
Primitive Variables.
Programming Fundamental Slides1 Data Types, Identifiers, and Expressions Topics to cover here: Data types Variables and Identifiers Arithmetic and Logical.
1 homework Due today: hw #1 (mailing list printout) readings to date: chapter 1 and chapter read appendix B (3 pages on DOS) and and.
Primitive Variables.
Variable, Constants and Calculations Dr Mohammad Nabil Almunawar.
Chapter 4 Literals, Variables and Constants. #Page2 4.1 Literals Any numeric literal starting with 0x specifies that the following is a hexadecimal value.
A Simple Java Program //This program prints Welcome to Java! public class Welcome { public static void main(String[] args) { public static void main(String[]
Operators and Expressions. 2 String Concatenation  The plus operator (+) is also used for arithmetic addition  The function that the + operator performs.
Programming Fundamentals. Overview of Previous Lecture Phases of C++ Environment Program statement Vs Preprocessor directive Whitespaces Comments.
# 1# 1 What is a variable that you create? What is a constant that you create? What is an intrinsic (built-in) constant? What variables are built in?
Programming with Microsoft Visual Basic th Edition
9/29/99B-1 CSE / ENGR 142 Programming I Variables, Values, and Types © 1998 UW CSE.
Variables Hold information that may be manipulated, used to manipulate other information or remembered for later use A storage location in memory (RAM)
1 Week 5 l Primitive Data types l Assignment l Expressions l Documentation & Style Primitive Types, Assignments, and Expressions.
CPS120: Introduction to Computer Science Variables and Constants.
Java – Variables and Constants By: Dan Lunney. Declaring Variables All variables must be declared before they can be used A declaration takes the form:
Variables in C Topics  Naming Variables  Declaring Variables  Using Variables  The Assignment Statement Reading  Sections
CMSC 104, Version 8/061L09VariablesInC.ppt Variables in C Topics Naming Variables Declaring Variables Using Variables The Assignment Statement Reading.
Chapter 3: Introducing the Microsoft.NET Framework and Visual Basic.NET Visual Basic.NET Programming: From Problem Analysis to Program Design.
CIS 338: VB Variables Dr. Ralph D. Westfall April, 2011.
Chapter 4: Variables, Constants, and Arithmetic Operators Introduction to Programming with C++ Fourth Edition.
A Sample Program #include using namespace std; int main(void) { cout
Making Interactive Programs with Visual Basic .NET
Chapter 4.  Variables – named memory location that stores a value.  Variables allows the use of meaningful names which makes the code easier to read.
Introduction C# program is collection of classes Classes are collection of methods and some statements That statements contains tokens C# includes five.
Chapter 2 Variables and Constants. Objectives Explain the different integer variable types used in C++. Declare, name, and initialize variables. Use character.
Bill Tucker Austin Community College COSC 1315
Egyptian Language School Computer Department
BASIC ELEMENTS OF A COMPUTER PROGRAM
Data Types, Arithmetic Operations
What's a Computer? Monitor Disk Main mouse Memory Keyboard Network
Data Types, Identifiers, and Expressions
Variables, Printing and if-statements
IDENTIFIERS CSC 111.
Data Types, Identifiers, and Expressions
Chapter 2 Edited by JJ Shepherd
Numbers.
Variables Numbers can be stored and retrieved while a program is running if they are given a home. The way that integers and decimal numbers are stored.
C++ Data Types Data Type
Visual Basic Numbers Chapter 3.3 Prepared By: Deborah 1/15/2019.
Chapter # 2 Part 2 Programs And data
CHAPTER FOUR VARIABLES AND CONSTANTS
Primitive Types and Expressions
Variables in C Topics Naming Variables Declaring Variables
Visual Basic Numbers Chapter 3.3 Prepared By: Deborah 7/9/2019.
Variables and Constants
Programming Fundamental-1
Presentation transcript:

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 to be able to perform calculations we will learn about Variables, constants Data types Hungarian notation Scope of a variable Operations on variables … and more!

110-D2 Computer and Memory Central Processing Unit Main Memory Monitor Disk Keyboard mouse Network Understand how the computer uses its memory from a programmer's point of view

110-D3 Memory and Data All data used by a program is stored in the memory of the computer (numbers, names…). Think of memory as a (huge) pile of boxes Each box has a number gives the location BUT can be interpreted in many ways by a program (a number, a letter..) Each box always contains a value: a succession of 0’s and 1’s

110-D4 Memory and Data ‘c’ Location 4 contains Location 2 contains the letter ‘c’ In a program do not use the location number (=address) explicitly: don’t want to say “take the content of box 4” would drive us crazy!

110-D5 Instead: Use a name to refer to the content of a given box a variable Rule of programming: A variable MUST be declared to indicate the type of the variable (is it a character (letter), an integer, a floating point number…?) VB.NET strictly enforces the rule. By default it has Option Explicit on. Don’t turn it off! It is also a good idea to turn Option Strict on to prevent accidental conversions between types (see later).

110-D6 Declaring Variables Many different types: some examples Dim intNumberOfChildren As Integer A VB language declaration VB key word. Reserve space in the memory int for integer (Hungarian notation) No space or periods in the variable name Can use underscores (_) Use meaningful names (NOT Dim n As Integer ) For integer An integer can be 1, -46, 236 (NOT 1.5, -2.3)

110-D7 Dim dblTemperature As Double for a floating point, that is 96.2, -14.9, -7.02e for a string: any combination of characters e.g. "123go", ", "BluE" (the content of a string is written between double quotes ("), e.g. strMessage = "Welcome to VB.NET") Dim strMessage As String

110-D8 _ precede the name of every variable, constants, or object with a lowercase prefix specifying the data type. (Hungarian notation: see list p 99) Naming Rules (1) To make your code easier to understand, use the following stylistic guidelines: _ Capitalize each first letter of each word of a name, e.g. intNumberOfChildren _ use letters, numbers: strEmployee1SSN _ can’t start with a number or underscore: _bad, 1_not_good _ Names can’t contain spaces or periods

110-D9 Naming Rules (2) _ meaningful names: Dim intAge As Integer NOT Dim a As Integer VB will help you as you type... _can’t be a VB.NET keyword: End, Dim, As... _NOT case sensitive: temperature is the same as Temperature _ length: practically, as long as you want (the limit is 16,383 characters, but...)

110-D10 Constants Within a program, some values do not change: e.g. value of pi = To avoid any accidental change, declare such values as constants: Const dblPI As Double = declares a constant Use only uppercase letters for the name (except for the prefix) Initialize the constant when declaring it (can’t do it anywhere else!) Can have the same types for constants as for variables Integer, Double, String... VB provides a set of built in constants. (intrinsic constants). You need to specify class name and constant name, e.g. Color.Red

110-D11 Some common types We have seen: String, Integer, Double Also: Uses lots of memory, not as efficient. Avoid if you can Boolean For logical values (True/False) Dim blnLightOn As Boolean Object When you don’t specify the type of a variable, VB.NET takes it as an object. An object type variable can hold any type of data. Dim objAnything Dim objSomething As Object optional Decimal For decimal fractions such as dollars and cents Dim decMyBalance As Decimal

110-D12 Storing values into variables Declare a variable gives a name to the content of a memory location We get a box. But how to put something in it? Or better said: How to store the value of a variable in the memory? One way: Use an assignment statement Dim strName As String strName = "Jane Beckmann" a declaration an assignment statement an expression (anything that has a value) Note: to get " in a string, write "" strDialog = "She said ""Well,...""" to get She said "Well,..."

110-D13 Processing an assignment statement Consider: dblPerimeter = dblPI*dblDiameter 1 Evaluate the right hand side (=expression) dlbPI*dblDiameter Note: can have intYear = intYear + 1 (NOT a mathematical equation!) 2 The value is stored in the left hand side, the assignment variable dblPerimeter