Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 7 Where Can I Store This?

Slides:



Advertisements
Similar presentations
Chapter 3: Using Variables and Constants Programming with Microsoft Visual Basic 2005, Third Edition.
Advertisements

Microsoft Visual Basic 2010: Reloaded Fourth Edition Chapter Eight Sub and Function Procedures.
Starting Out with C++, 3 rd Edition 1 Chapter 1. Introduction to Computers and Programming.
1.
An Introduction to Programming with C++ Fifth Edition Chapter 4 Chapter 4: Variables, Constants, and Arithmetic Operators.
An Introduction to Programming with C++ Fifth Edition Chapter 4 Chapter 4: Variables, Constants, and Arithmetic Operators.
Data Types and Operations Programming Fundamentals (Writing Code)Programming Fundamentals (Writing Code)
VB Code Statements 3 types of VB statement The Remark statement, known as comments, are used for project documentation only Begin with an apostrophe Not.
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.
Moving To Code 3 More on the Problem-Solving Process §The final step in the problem-solving process is to evaluate and modify (if necessary) the program.
Chapter 3: Introduction to C Programming Language C development environment A simple program example Characters and tokens Structure of a C program –comment.
Chapter Three Using Variables and Constants Programming with Microsoft Visual Basic th Edition.
Variables & Math Operators CE 311 K - Introduction to Computer Methods Daene C. McKinney.
Apply Sub Procedures/Methods and User Defined Functions
Variables, Constants, Methods, and Calculations Chapter 3 - Review.
Visual Basic Fundamental Concepts. Integrated Development Enviroment Generates startup form for new project on which to place controls. Features toolbox.
Variables and Constants
Chapter 3: Using Variables and Constants
Programming with Microsoft Visual Basic th Edition CHAPTER THREE USING VARIABLES AND CONSTANTS.
Tutorial 11 Using and Writing Visual Basic for Applications Code
CHAPTER THREE Representing Data: Constants and Variables.
National Diploma Unit 4 Introduction to Software Development Data types, variables and constants.
Chapter 3 Part 11 Variables, Constants, and Calculations Chapter 3 Section 3.3 Chapter 3 Section 3.4.
Lecture 8 Visual Basic (2).
Computer Programming TCP1224 Chapter 4 Variables, Constants, and Arithmetic 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.
Using Data Within a Program Chapter 2.  Classes  Methods  Statements  Modifiers  Identifiers.
Introduction to VB.NET 2005 Dr. McDaniel IDS4704 Spring 2005.
Course Title: Object Oriented Programming with C++ instructor ADEEL ANJUM Chapter No: 03 Conditional statement 1 BY ADEEL ANJUM (MSc-cs, CCNA,WEB DEVELOPER)
Programming with Visual C++: Concepts and Projects Chapter 2B: Reading, Processing and Displaying Data (Tutorial)
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 3 Variables, Constants, Methods, and Calculations.
CS0004: Introduction to Programming Project 1 – Lessons Learned.
3 1 Sending Data Using an Online Form CGI/Perl Programming By Diane Zak.
Data Types and Variables. Data Type! Computers are all about Data! Data can be in the form of Text Dates Sounds Pictures.
Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 8 What’s Wrong with It?
Variables & Function Calls. Overview u Variables  Programmer Defined & Intrinsic  Data Types  Calculation issues u Using Functions  The val() function.
1 Advanced Computer Programming Lab Calculator Project.
Microsoft Visual Basic 2010: Reloaded Fourth Edition Chapter Three Memory Locations and Calculations.
Chapter 3 w Variables, constants, and calculations DIM statements - declaration temporary memory locations identifier, data type, scope data types - values.
Chapter 4 Variables and constants. 4.1 Variables -Use of variables is good programming style -easier to modify -easier for a programmer to understand.
Overview of C. C—a high-level programming language developed in 1972 by Dennis Ritchie at AT&T Bell Laboratories. We will discuss: –the elements of a.
Programming with Microsoft Visual Basic 2008 Fourth Edition Chapter Three Using Variables and Constants.
Programming with Microsoft Visual Basic th Edition
Tutorial 3: Using Variables and Constants1 Tutorial 3 Using Variables and Constants.
Visual Basic CDA College Limassol Campus COM123 Visual Basic Programming Semester C Lecture:Pelekanou Olga Week 3: Using Variables.
Tutorial 3: Using Variables and Constants1 Tutorial 3 Using Variables and Constants.
CHAPTER THREE Representing Data: Constants and Variables.
Microsoft Visual Basic 2012 CHAPTER FOUR Variables and Arithmetic Operations.
Chapter 4: Variables, Constants, and Arithmetic Operators Introduction to Programming with C++ Fourth Edition.
Addison Wesley is an imprint of © 2011 Pearson Addison-Wesley. All rights reserved. Addison Wesley is an imprint of Chapter 3 Variables and Calculations.
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.
Slide 1 Chapter 3 Variables  A variable is a name for a value stored in memory.  Variables are used in programs so that values can be represented with.
Programming with Microsoft Visual Basic 2012 Chapter 3: Using Variables and Constants.
© 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.
Chapter 2 Variables and Constants. Objectives Explain the different integer variable types used in C++. Declare, name, and initialize variables. Use character.
Representing Data: Constants and Variables
Visual Basic Fundamental Concepts
A variable is a name for a value stored in memory.
Chapter 3: Using Variables and Constants
Variables and Arithmetic Operations
Visual Basic..
Chapter 3 The DATA DIVISION.
CIS16 Application Development Programming with Visual Basic
CHAPTER FOUR VARIABLES AND CONSTANTS
An Introduction to Programming with C++ Fifth Edition
Visual Basic Numbers Chapter 3.3 Prepared By: Deborah 7/9/2019.
Variables and Constants
Presentation transcript:

Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 7 Where Can I Store This?

Clearly Visual Basic: Programming with Visual Basic Design the following Interface, and program using methods learned in Chapter 6

Objectives Declare variables and named constants Convert text to a numeric data type using the TryParse method Understand the scope and lifetime of variables Desk-check a program Format a program’s numeric output Clearly Visual Basic: Programming with Visual Basic 20083

Using Storage Bins Internal memory –Composed of memory locations Memory location –Can hold only one item of data at a time To reserve a memory location: –Use a Visual Basic instruction that assigns both a name and data type to the memory Location Memory locations are called variables Clearly Visual Basic: Programming with Visual Basic 20084

So, What’s Your Type? Variables –Come in different types and sizes Item that a variable will accept for storage –Determined by the variable’s data type Decimal variables –Take twice as much room in memory as Double variables Clearly Visual Basic: Programming with Visual Basic 20085

6

Let’s Play the Name Game Variable name –Should be descriptive –Should be meaningful right after you finish a program and years later –No punctuation marks or spaces allowed –Cannot be a reserved word, such as Val Clearly Visual Basic: Programming with Visual Basic 20087

8

You’ll Need a Reservation Reserving a variable –Often referred to as declaring a variable Dim statement –Declares a variable in an event procedure Clearly Visual Basic: Programming with Visual Basic 20089

10

11 Mini Quiz Which of the 3 data types are appropriate for storing the number of disks purchased by a customer: a. Integer b. Decimal C. Double Which of the following is not a valid name for a variable? A. decRate B. dblRate C. decRate_Of_Pay D. dblPay.rate Write a Dim statement to declare a Double variable named dblHoursWorked Dim dblHoursWorked as Double

How Many Variables Should I Use? Circle Area problem’s solution (Figure 7-5) –Utilizes two different variables One to store the output item and the other to store the input item Before coding the Circle Area application –View the Ch07-Circle Area video Clearly Visual Basic: Programming with Visual Basic

Clearly Visual Basic: Programming with Visual Basic

Clearly Visual Basic: Programming with Visual Basic 2008 The TryParse Method Every numeric data type in Visual Basic has: –A TryParse method that can be used to convert text to that numeric data type Syntax of the TryParse method –dataType.TryParse(text, variable) 14

15

Clearly Visual Basic: Programming with Visual Basic

Dim Area as a Double Dim PI as a Constant- Double Dim Radius as a double Using TryParse-change the Radius to a numeric variable Double.TryParse(txtRadius.Text, dblRadius)

Check, Please … I’m Ready to Go Desk-check table for a program –Will contain one column for each variable Desk-check the Circle Area program –Use radius values of 6.5 and 10 Clearly Visual Basic: Programming with Visual Basic

Clearly Visual Basic: Programming with Visual Basic

Using Constants to Keep Things … Well, the Same Named constant –Memory location whose value cannot change while the application is running –Used to give names to constant values –Makes code more self-documenting and easier to modify –Created using the Const statement Clearly Visual Basic: Programming with Visual Basic

Dressing Up the Output Formatting –Specifying number of decimal places and the special characters to display in a number variable.ToString(formatString) –Formats a number string –Text enclosed in double quotation marks Clearly Visual Basic: Programming with Visual Basic

Try entering 6.5 for the Radius This is what your results should look like: Clearly Visual Basic: Programming with Visual Basic

23

Private Sub btnCalc_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCalc.Click ' calculates and displays the area of a circle ' declare named constant Const dblPI As Double = ' declare variables Dim dblArea As Double Dim dblRadius As Double ' assign radius to a variable Double.TryParse(txtRadius.Text, dblRadius) ' calculate area dblArea = dblRadius * dblRadius * dblPI ' display area lblArea.Text = dblArea.ToString("N2") End Sub

25 1.Which of the following declares a variable named intNumSold? A. Dim intNumSold As Integer B. Dim As Integer intNumSold C. Const intNumSold As Integer D. None of the Above 2.If you enter A34 in a txtPrice textbox, what does the TryParse control assign to it? Decimal.TryParse(txtPrice.Text, decPrice) A. A B. A34 C. 0 D Which adds intScore and intScore2 and then multiplies the sum by 2, assigning the results to intTotal? A. intScore1 +intScore2 *2 = intTotal B. (intScore1 +intScore2)*2= intTotal C. intTotal = IntScore1 + intScore2 * 2 D. None of these 4.Which of the following statements declares the decRate as a constant set to.15? A. Con decRate as Decimal =.15 B. Const decRate as Decimal =.15 C. Constant decRate as Decimal =.15 D. None of these 5.Which formats dblDue with dollar sign and 2 decimal places? A. lblDue.text = dblDue.ToString(“C2”) B. lblDue.Text = ToSting(dblDue, “C2”)

Clearly Visual Basic: Programming with Visual Basic Jackson College charges $1800 for room and board plus $100 per semester hour. The Cashier will enter the number of hours the student enrolls in. The output is Total Cost Assign the variable txtHours for the textBox using the TryParse command. Format the output as currency

Design and program the following Concert Revenue Calculator

Finding the area, and number of pizza slices from a given Radius Area = Pi * R^2

Open SUN Project and Dimension decHours, decPayRate, decGross, decFwt, decFica, decState, decNet As Decimal

Clearly Visual Basic: Programming with Visual Basic 2008 Summary Internal memory of a computer –Composed of memory locations Memory location –Can store only one value at any one time Value in a variable –Can change as the application is running Integer data type –Stores integers 31

Clearly Visual Basic: Programming with Visual Basic 2008 Summary (continued) Dim statement –Reserves a procedure-level variable TryParse method –Converts text to numbers Const statement –Declares named constants ToString method –Converts a number to formatted text 32