{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Ch.9 varriables errors

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

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

Click to edit Master subtitle style Using Variables and Constants in VBA & Troubleshooting Programming Errors Selected topics from Chapter 9 11

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

View Full Document
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
Variables & Constants 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

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

View Full Document
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
Declaring Variables & Constants 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

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

View Full Document
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).
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### 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
Ask a homework question - tutors are online