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.

Slides:



Advertisements
Similar presentations
Operators & Identifiers The Data Elements. Arithmetic Operators exponentiation multiplication division ( real ) division ( integer quotient ) division.
Advertisements

Objectives Understand the software development lifecycle Perform calculations Use decision structures Perform data validation Use logical operators Use.
VB Numbers and Strings School of Business Eastern Illinois University (Week 4, Monday 2/03/2003) © Abdou Illia, Spring 2003.
©2004 Brooks/Cole Chapter 2 Variables, Values and Operations.
Bellevue University CIS 205: Introduction to Programming Using C++ Lecture 3: Primitive Data Types.
CMT Programming Software Applications
 2002 Prentice Hall. All rights reserved. 1 Intro: Java/Python Differences JavaPython Compiled: javac MyClass.java java MyClass Interpreted: python MyProgram.py.
Data types and variables
 2002 Prentice Hall. All rights reserved. 1 Chapter 2 – Introduction to Python Programming Outline 2.1 Introduction 2.2 First Program in Python: Printing.
Chapter 2 Data Types, Declarations, and Displays
Chapter 3: Introducing the Microsoft.NET Framework and Visual Basic.NET Visual Basic.NET Programming: From Problem Analysis to Program Design.
To type the VB code behind the command button (named cmdPush), Double-Click on the Push Me (caption) command button As a result the Visual Basic Code Window.
Objectives You should be able to describe: Data Types
A First Book of ANSI C Fourth Edition
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved. 1 6 Enhancing the Inventory Application Introducing Variables, Memory Concepts and.
 2003 Prentice Hall, Inc. All rights reserved. 1 Introduction to C++ Programming Outline Introduction to C++ Programming A Simple Program: Printing a.
A Variable is symbolic name that can be given different values. Variables are stored in particular places in the computer ‘s memory. When a variable is.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
06/10/ Working with Data. 206/10/2015 Learning Objectives Explain the circumstances when the following might be useful: Disabling buttons and.
1 Chapter 3 – Variables, Input, and Output 3.1 Numbers 3.2 Strings 3.3 Input and Output.
Program A computer program (also software, or just a program) is a sequence of instructions written in a sequence to perform a specified task with a computer.
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
Input, Output, and Processing
Chapter 2: Using Data.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-1 Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.
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.
C++ Programming: Basic Elements of C++.
Input Textboxes Input Boxes Different than textboxes Good for small amount of input (form full of textboxes is not nice) X = Inputbox(“prompt message”,
Operators & Identifiers The Data Elements. Arithmetic Operators exponentiation multiplication division ( real ) division ( integer quotient ) division.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 3 Variables, Constants, Methods, and Calculations.
Data Types and Variables. Data Type! Computers are all about Data! Data can be in the form of Text Dates Sounds Pictures.
Variables & Function Calls. Overview u Variables  Programmer Defined & Intrinsic  Data Types  Calculation issues u Using Functions  The val() function.
Chapter 2 Variables.
Chapter 4 Variables and constants. 4.1 Variables -Use of variables is good programming style -easier to modify -easier for a programmer to understand.
Java Programming, Second Edition Chapter Two Using Data Within a Program.
A Simple Java Program //This program prints Welcome to Java! public class Welcome { public static void main(String[] args) { public static void main(String[]
COMP Primitive and Class Types Yi Hong May 14, 2015.
Operators & Identifiers The Data Elements. Arithmetic Operators exponentiation multiplication division ( real ) division ( integer quotient ) division.
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
Programming Fundamentals. Overview of Previous Lecture Phases of C++ Environment Program statement Vs Preprocessor directive Whitespaces Comments.
VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 2A Reading, Processing and Displaying Data (Concepts)
Programming Fundamentals. Summary of previous lectures Programming Language Phases of C++ Environment Variables and Data Types.
VB CSCI130 Instructor: Dr. Imad Rahal LAYEROrder Application SW: Excel & Access2 High-order P.L.: Visual Basic1 Low-order P.L.: Assembly3 System Software:
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.
Microsoft Visual Basic 2012 CHAPTER FOUR Variables and Arithmetic Operations.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 2 Introduction to C++
Data and variables in Visual Basic. Annoucement Lecture on Thursday 7:30PM C106 Visual Basic download: 
Creation of Variables with Numeric, alphanumeric, date, picture, memo data types Constant - A quantity that does not change during the execution of a program.
CIS 338: VB Variables Dr. Ralph D. Westfall April, 2011.
Chapter 4: Variables, Constants, and Arithmetic Operators Introduction to Programming with C++ Fourth Edition.
1 2. Program Construction in Java. 01 Java basics.
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.
Chapter 3 - VB 2008 by Schneider1 Chapter 3 – Variables, Input, and Output 3.1 Numbers 3.2 Strings 3.3 Input and Output.
CS0007: Introduction to Computer Programming Primitive Data Types and Arithmetic Operations.
A variable is a name for a value stored in memory.
Chapter 2 Variables.
Topics Designing a Program Input, Processing, and Output
Variables and Arithmetic Operations
Introduction to C++ Programming
Numbers.
Chapter 2 Variables.
Topics Designing a Program Input, Processing, and Output
Introduction to Programming
Topics Designing a Program Input, Processing, and Output
Unit 3: Variables in Java
Chapter 2 Variables.
Presentation transcript:

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 Also change caption Textbox  txtTextBoxName E.g. txtInputBox Also change Text (to empty) Label  lblLabelName E.g. lblDescribeInput Also change caption Button  cmdButtonName E.g. cmdComputeButton Also change caption PictureBox  picPictureBoxName E.g. picOutputBox

Simple Calculations Algorithm Get temperature in Celsius, call it Cel Convert using Fah = 9/5*Cel+32 Print result in picture box Show code: option Explicit Private Sub cmdConvertButton_Click() (1) ‘program to convert Celsius to Fahrenheit (2) Dim Cel As Single ‘declare a variable of type float … no space in name Dim Fah As Single ‘declare a variable of type float… MUST Starts with a letter (3) Cel = txtInputText.Text ‘Read value input in Textbox into variable C (4) Fah = / 5 * Cel ‘Compute Fah (5) picOutputPicture.Print Cel; “ degrees Celsius is"; Fah; “ degrees Fahrenheit.“ ‘Print result End Sub

Simple Calculations 'program to convert Celsius to Fahrenheit a comment describing what the subroutine does…for the reader Everything starting with a quotation mark (‘) is ignored by the computer For longer programs, we need more comments spread throughout the program Cel & Fah are variables that represents the memory registers used to store the floating-point values

Variable Declarations Declaring variables At the beginning of the code Dim variable_name As Type Dim C As Single The variable name or a string of characters (letters, numbers, and others) MUST Start with a letter NO SPACES Name related to the value it is storing (REQUIRED)

Variable Declarations Type Integer for short integers (2’s complements) 2 bytes -2,147,483,648 through 2,147,483,647 (signed) Long for long integers (double precision 2’s complements) 4 bytes 9,223,372,036,854,775,808 through 9,223,372,036,854,775,807 Single for short real numbers (floating-point) 4 bytes E+38 through E-45 for negative E-45 through E+38 for positive Double for long real numbers (double precision floating-point) 8 bytes E+308 through E-324 for negative E-324 through E+308 for positive Boolean: True or False 2 bytes String for character strings (ASCII) Variable length 0 to approximately 2 billion Unicode characters

Variable Declarations After declaring a variable, we initialize it Dim A As Integer A = 10 If not provided All numbers are set to 0 Strings to empty Booleans to false VB does not force us to declare them Using Option Explicit Placed at the top of code module sheet Forces all variables to be declared on that form A MUST IN THIS COURSE

Simple Calculations Fah = / 5 * Cel We need to divide by 5 multiply by C Whenever a variable is used, the computer uses the corresponding value stored in the variable add 32 BUT IN WHAT ORDER?

Order of Precedence Arithmetic operations What happens when we have more than 1 in the same equation? Addition+ Subtraction- Multiplication* Division/ Exponentiation^ F = 9 / 5 * C + 32 (), ^, * or /, + or – Handled from left to right A = 3*8/2^ ^2 = 4  A = 3*8/ *8 = 24  A = 24/ /4 = 6  A = = 8  A = = 3  A = 3

Simple Calculations picOutputPicture.Print Cel; "degrees Celsius is"; Fah; "degrees Fahrenheit.“ An object function The value in Cel is printed first A semi-colon is used to separate the numbers and the following or preceding words Text between double quotes is printed as is All printing is done in the Picture Box (picOutputPicture) Every time we click the button, the program prints the required output What happens if we click it twice? i.e. what happens to the old output when there is new output picOutputPicture.Cls At the beginning of the code Clears all previous output

Simple Calculations To add code for the cmdExitButton We need to double click it in design mode It is required to include an cmdExitButton on every form Good programming practice Indentation makes things clearer for the reader Private Sub ExitButton_Click() End End Sub

Numeric Functions Sqr(X) Square root Sqr(4) Int(X) Int(2.1234) Round(X) To the nearest integer Round(2.45) Abs(X) Abs(-34) Log(X) Log(4) Program: calculate the roots of a quadratic equation given a, b and c Private Sub Quadraticbutton_Click() Dim A As Integer, B As Integer, C As Integer Dim R1 As Double, R2 As Double A = txtA.Text B = txtB.Text C = txtC.Text R1 = (-B+Sqr(B^2-4*A*C))/(2*A) R2 = (-B-Sqr(B^2-4*A*C))/(2*A) Results.Print “Roots are:”;R1;R2 End Sub

Input Textboxes Input Boxes Different than textboxes Good for small amount of input (form full of textboxes is not nice) X = Inputbox(“prompt message”, “title message”) The input is assigned to variable X when the use hits OK A = Inputbox(“Enter an exam score”,”Exam 1”)

Output Pictureboxes Message Boxes For output specially in situations of errors different than pictureboxes MsgBox “prompt message”,,“title message” MsgBox “Sorry but you must enter a positive number”,, “Error”

Output Display (pictureboxes) Spacing, (comma) … ALIGN OUTPUT Every picture box is divided into 14-space print zones Jumps to the next zone (does not jump 14 spaces necessarily!) From its current location (its current 14-space zone) Results.Print 5,30,2 Tab function: Tab(X) Followed by a ; (automatically inserted by VB) leaves X spaces from start Pushes any overlap to new lines Results.Print Tab(2); “Hi!” Results.Print Tab(2); “Hi!”; Tab(2); “Bi!”; What should the second 2 be to print on the same line A comma or semi-colon at the end of a print statement prints next print statement on the same line

Output Display FormatCurrency(x,y) --- y is 2 by default x is the decimal number to be formatted y is the number of digits allowed after the decimal point (rounding) Extra 0s are appended Adds a $ sign and commas if needed FormatCurrency( ,2) = $1, FormatCurrency(1234.2,2) = ? FormatNumber(x,y) --- y is 2 by default Rounds x to the nearest number of digits after the decimal point specified by y FormatNumber(0.5235) = 0.52 FormatNumber(0.5235,3) = 0.524

Variable Scope Where we declare a variable defines its scope i.e. where it is known Determines what subroutines can access it Subroutine-level: Within a subroutine  only in that subroutine Form-level: At top of the form (before the code for the first subroutine under Option Explicit) Not within any subroutine Accessible by all SUBROUTINES for that form