Ch.9 varriables errors

Ch.9 varriables errors - Using Variables and Constants in...

Info iconThis preview shows pages 1–7. Sign up to view the full content.

View Full Document Right Arrow Icon
Click to edit Master subtitle style Using Variables and Constants in VBA Troubleshooting Programming Errors Selected topics from Chapter 9 11
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Handling Program Data n Programs process sets of data, such as: n Calculating invoice totals based on invoice subtotal, tax rate, and discount rate n Calculation for one invoice using actual values: n 1000 + (1000 * .05) – (1000 * 0.1) = 950 ( subtotal + tax discount = total ) n For a program to calculation many different invoices, use a set of variables instead of the actual values. total = subtotal * (1 + taxrate) – subtotal * discount (The resulting value on the right is assigned to the variable on the left.) 22
Background image of page 2
n Used to carry or move data through the program while it runs n Definition: Named locations in volatile memory (a.k.a. RAM) where data is stored temporarily n Variables handle data that change from one data set to another while the program is running, such as lastName, or itemPrice. n Constants handle data that only the programmer changes and does not change its value from one data set to another during program execution, such as TAX_RATE, DISCOUNT_RATE. 33
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Relate to Excel Formula References n Variables are like relative references. n Relative references represent formula inputs that change as the formula is pasted to a new row or column. n The values held by variables change as each new set of data is calculated. n Constants are like absolute references. n Absolute references represent formula inputs that remain the same when the formula is pasted to new columns or rows. (Think about assumption values.) n An input value that is changed only by the programmer (not when the program is running). 44
Background image of page 4
n “Declare” (define) a variable or constant before using it. n In VBA, may use without explicit declaration, but not a good practice. n By declaring explicitly by the developer, can more easily track and troubleshoot variables. n Declaration includes (more details on next slide) n Language keywords for declaring variables and constants. n A name for the variable or constant, also called the identifier n Some rules exist for naming variables (i.e. cannot begin with a number or special character, usually a length limit) n Data type (number, text, date, etc.) n For constants only, an initial value 55
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Variable/Constant Declaration Syntax in VBA n Programming Keywords (specific to each programming language) n "Dim" (short for “dimension”) is keyword for declaring variables in VBA n "Const" is keyword for declaring constants in VBA n One-word name , also called identifier n Variable name example: lastName, last_name n Constant name example: TAXRATE or TAX_RATE n Data Type n Examples: String, Integer, Single, Double, Date, Boolean, Range, Worksheet (and many many more VBA types). n
Background image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 08/15/2011 for the course ACIS 2504 at Virginia Tech.

Page1 / 28

Ch.9 varriables errors - Using Variables and Constants in...

This preview shows document pages 1 - 7. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online