Visual Basic for Applications/Conditions

This lesson introduces conditions.

Objectives and Skills
Objectives and skills for conditions include:
 * Applying If...Then and If...Then...Else decision structures to control execution of code
 * Applying a Select Case decision structure to control execution of code

Readings

 * 1)  Conditional (computer programming)
 * 2)  Switch statement
 * 3) Microsoft: Variant Data Type
 * 4) Microsoft: Using If...Then...Else Statements
 * 5) Microsoft: Using Select Case Statements

Activities
In these activities you will create macros that use input boxes to obtain user input, variables and conditions to perform calculations, and message boxes to display results. Your macros should include Option Explicit, Dim, InputBox, MsgBox, titles on the dialog boxes, an icon on the message box, and use appropriate data types for your variables.


 * 1) Logical Operators
 * 2) Review Microsoft: Logical Operators.
 * 3) Create a macro that  uses different values and conditions to show that in VBA zero is false and anything non-zero is true. Also show that the explicit value of False is 0 and the explicit value of True is -1.
 * 4) Age Calculations - If/ElseIf/Else
 * 5) Create a macro that asks the user how old they are in years.  Then ask the user if they would like to know how old they are in months, days, hours, or seconds. Use an If/ElseIf/Else statement to display their approximate age in the selected time frame.
 * 6) Temperature Conversion - If/ElseIf/Else
 * 7) Review MathsIsFun: Conversion of Temperature.
 * 8) Create a macro that asks the user if they would like to convert Fahrenheit to Celsius or Celsius to Fahrenheit. Use an If/ElseIf/Else statement to determine their selection and then gather the appropriate input and calculate and display the converted temperature.
 * 9) Area Calculations - If/ElseIf/Else
 * 10) Review MathsIsFun: Area of Plane Shapes.
 * 11) Create a macro that asks the user what shape they would like to calculate the area for. Use an If/ElseIf/Else statement to determine their selection and then gather the appropriate input and calculate and display the area of the shape.
 * 12) Age Calculations - Select Case
 * 13) Create a macro that asks the user how old they are in years.  Then ask the user if they would like to know how old they are in months, days, hours, or seconds. Use a Select Case statement to display their approximate age in the selected time frame.
 * 14) Temperature Conversion - Select Case
 * 15) Review MathsIsFun: Conversion of Temperature.
 * 16) Create a macro that asks the user if they would like to convert Fahrenheit to Celsius or Celsius to Fahrenheit. Use a Select Case statement to determine their selection and then gather the appropriate input and calculate and display the converted temperature.
 * 17) Area Calculations - Select Case
 * 18) Review MathsIsFun: Area of Plane Shapes.
 * 19) Create a macro that asks the user what shape they would like to calculate the area for. Use a Select Case statement to determine their selection and then gather the appropriate input and calculate and display the area of the shape.