70 likes | 156 Views
Program Statements …. …. Data Values …. …. Computer Memory Programs Objects and object properties Instructions 1. Input 2. assign values to memory 3. Calculate 4. compare and select 5. repeat a section of code 6. output
E N D
Program Statements …. ….. Data Values …. ….. • Computer Memory • Programs • Objects and object properties • Instructions • 1. Input • 2. assign values to memory • 3. Calculate • 4. compare and select • 5. repeat a section of code • 6. output • Data – Values of Variables (and constants) • All these must be stored as a particular type of data
Types of Variables currency string (text) integer single (Single precision floating point) (decimal number) double (double precision floating point) (bigger decimal number) boolean (true or false) etc. (see page 62) Declaring Variables: Objects on the form don’t have to be declared (They are already defined!) All Variables (other than Objects) will need to be declared: Dim Taxes as currency Dim CustomerID as integer, CustName as string Always use “option explicit” statement in “general code” section.
Variable Types and Variable Declaration Variable Types Single, double, currency, integer, long, date, boolean, string Declaration statements (Dim) Option Explicit and setting the “require variable declaration” property in tools/options Code Windows and the General Code Window The “Scope” of variable declaration Suggestion: define all variables in the General Code Window Constants and declaring constants (Const) Example: Declare a variable in the code for command button click, then use that variable in code for a different command button click.
Assignment statements Variable = Expression NetPay = RegularPay + OverTimePay Answer = 6 + 2 / 2 ^ 2 + 1 Expressions (arithmetic, logical) Order of operations [(), ^, -, *, /, \, Mod, +, -] Parentheses Functions – Val(), Str(), Format(variable, “currency”), CCur() IsNumeric()
Code Windows The Object List General Form objects on the form (labels, text boxes, etc.) The Event List Click Double Click Load (for the Form) Key Press Got Focus
Counters In the Initialization Code (Perhaps in the Form Load Event)(executed once): NumberOfEmployeesProcessed = 0 - In the Loop Code (executed repeatedly): - - GrossPay = RegularPay + OverTimePay - NumberOfEmployeesProcessed = NumberOfEmployeesProcessed + 1
Counters and Sums In the Initialization Code (Perhaps in the Form Load Event)(executed once): NumberOfEmployeesProcessed = 0 TotalPayroll = 0 - In the Loop Code (executed repeatedly): - - GrossPay = RegularPay + OverTimePay - NumberOfEmployeesProcessed = NumberOfEmployeesProcessed + 1 TotalPayroll = TotalPayroll + GrossPay