Exam Study Guide: Chapter 3
(Object-Oriented Fundamentals in
[Link])
This comprehensive guide compiles and organizes all critical concepts, syntax rules, structures,
📚 Table of Contents
and exam-focused explanations from Chapter 3.
1. Language Fundamentals
○ Variables and Data Types
○ Constants
○ Operators and Precedence Hierarchy
○ Expressions and String Concatenation
○ Displaying Output
○ Program Comments and Library Functions
2. Control Flow
○ Branching Decision Structures
○ Select Case Structures
○ Looping and Iteration
○ Loop Exit and Termination Controls
3. Object-Oriented Core Concepts
○ Classes vs. Objects
○ Methods (Subroutines vs. Functions)
○ Events
○ Classes vs. Components
1. Language Fundamentals
[Link] is a strongly typed language, meaning every variable is mapped to a specific data
type, and data type rules are strictly enforced at runtime and compile-time.
Variables and Data Types
Variables are designated storage locations in memory used to hold temporary program values.
● Declaration Syntax: Always declared using the Dim keyword in the general declarations
or local procedural blocks.
● Examples:
Dim password As String
Dim firstnum As Integer
Dim doDate As Date
Dim userAge As Integer = 25 ' Declaring & initializing
simultaneously
Core Data Types to Remember:
Data Type Description Example Value
Integer Whole numbers without 123, -123
decimal places.
Double Floating-point numbers 19.99, -0.005
(decimals).
Char / String Single character (Char) or "Hello World"
blocks of text (String).
Boolean Logical state containing only True or False
two states.
Date Dates, represented in code #1/20/2002#
wrapped in hashes.
Constants
Constants hold unchallengeable values that are known at compile time and cannot change for
the duration of the program.
● Declaration Keyword: Const
● Syntax Example: ```vb Const deadline As Date = #1/20/2002#
● ⚠️ Exam Trap: Any attempt to reassign a value to a defined constant anywhere else in
the code will result in a run-time error.
Operators and Precedence Hierarchy
When evaluating equations, [Link] follows a strict mathematical operator hierarchy
(precedence).
🧮 Arithmetic Operators (In Order of Precedence)
1. Exponential (^): Calculates powers (e.g., 2 \wedge 4 = 16).
2. Multiplication (*) & Division (/): Standard mathematical scaling and fractional division
(e.g., 5 / 2 = 2.5).
3. Integer Division (\): Divides the operands but completely discards decimal places without
rounding (e.g., 5 \backslash 2 = 2).
4. Modulus (Mod): Returns only the remainder resulting from an integer division (e.g., 15
\text{ Mod } 4 = 3).
5. Addition (+) & Subtraction (-): Lowest precedence arithmetic operators.
Arithmetic Conversion Rules to Math Notation:
● The VB expression a / b * c evaluates from left to right as:
● The VB expression b ^ 2 - 4 * a * c translates mathematically to:
● An algebraic expression like 2(x_1 + 3x_2) must be written in [Link] with explicit
multipliers:
2 * (x1 + 3 * x2)
String Expressions & Concatenation
● Numerical arithmetic operations cannot be performed on string variables or constants.
● Strings can be combined (concatenated) using either the & operator (highly
recommended in [Link]) or the + operator.
● Example:
Dim str1 As String = "Hello"
Dim str2 As String = "welcome"
' Evaluates to: "Hello welcome mydear"
Dim result As String = str1 & " " & str2 & " mydear"
Relational & Logical Operators
Relational Operators
Used to compare values. They return a Boolean value (True or False).
● = (Equal to)
● <> (Not Equal to) — Notice this is unique compared to other C-style languages (!=)
● > (Greater than)
● < (Less than)
● >= (Greater than or equal to)
● <= (Less than or equal to)
String Comparison Rules:
Strings are compared left-to-right character-by-character based on their ASCII index value.
● Rule 1: Uppercase letters are mathematically less than lowercase letters:
● Rule 2: Numeric character symbols are mathematically less than letter symbols.
● Case Correction: Because casing differences affect evaluations, you can safely compare
strings using conversion helper methods like UCase() or LCase().
Logical Operators
Used to combine individual relational expressions into compound checks.
● And: Evaluates to True only if the conditions on both sides are true.
● Or: Evaluates to True if at least one condition on either side is true.
● Not: Inverts the truth state of a condition (negates).
Displaying Output (Form-based & Console-based)
● Print Statement: Historically used in classic visual forms to write raw textual data starting
in the upper-left corner of the active form.
● Formatting Syntaxes:
○ Separating items with a comma (,) tabs output values into preset column blocks.
○ Separating items with a semicolon (;) chains output items directly next to each
other.
● Modern Alternative: In Console applications, use [Link]().
Program Comments
Comments are non-executable statements used exclusively to document your code for human
readability.
● Syntax: A single apostrophe (') followed by your text.
● Example:
' Program to calculate roots
x1 = (-b + root) / (2 * a) ' Calculates first root
Library Functions
[Link] features robust built-in library helper functions. They are called by using their name
followed by parameters wrapped in parentheses.
● Examples: Sqrt(), Pow(), Sin(), Cos(), Tan().
2. Control Flow
Control flow determines the specific path of execution your program follows when compiling and
running.
Branching Structures
Branching structures choose which segment of code to run depending on Boolean conditional
logic evaluations.
1. If...Then
Executes code only if a condition resolves to true.
If condition Then
' Expressions run here
End If
● Syntax Rule: The keyword Then must be on the same line as If. End If must reside on its
own line.
2. If...Then...Else
Provides a binary fallback option.
If condition Then
' Executes if True
Else
' Executes if False
End If
3. ElseIf Ladder
Checks multiple sequential conditions. As soon as a single match is found, that block runs and
the program exits the entire structure.
If mark >= 75 Then
Print "A-Grade"
ElseIf mark >= 60 And mark < 74 Then
Print "B-Grade"
Else
Print "D-Grade"
End If
Select Case Structures
A cleaner, highly readable alternative to a massive ElseIf ladder. It compares a single
expression against various possibilities.
Select Case expression
Case value1
' Statements
Case value2, value3 ' Checks multiple comma-separated values
' Statements
Case Else
' Default fallback executed if no prior cases match
End Select
💡 Critical Syntaxes for Case Evaluation:
● The Is Keyword: Must be used when checking conditions involving relational operators
(e.g., Case Is >= 85).
● The To Keyword: Used to check inclusive numeric spans (e.g., Case 50 To 59).
● Example Case block:
Select Case mark
Case Is >= 85
[Link] = "Excellence"
Case 70 To 84
[Link] = "Good"
Case Else
[Link] = "Need to work harder"
End Select
Looping and Iteration
Looping repeatedly processes statements until specific parameters are satisfied.
1. For...Next Loop (Counted Loop)
Used when the total number of loops needed is known in advance.
For loopindex = initial_value To final_value [Step increment]
' Repeated expressions
Next [loopindex]
● Step Size: Determines the value added to the index counter after each pass. Can be
positive, negative, integer, or decimal.
● Counting Backward: Set a negative Step value (e.g., For A = 10 To 1 Step -1).
2. Do...Loop (Conditional Loop)
Used when loops depend on dynamic conditions. These are divided into Pre-Test and
Post-Test variations.
● Pre-Test Loops (Checks condition before executing the loop block):
' Executes as long as condition is TRUE
Do While condition
' Statements
Loop
' Executes as long as condition is FALSE
Do Until condition
' Statements
Loop
● Post-Test Loops (Checks condition after executing, ensuring the block runs AT
LEAST ONCE):
' Executes once, then repeats while condition is TRUE
Do
' Statements
Loop While condition
' Executes once, then repeats until condition becomes TRUE
Do
' Statements
Loop Until condition
3. While...Wend Loop
An alternative conditional loop that executes as long as a condition evaluates to true (evaluated
at the start of each pass).
While logical_expression
' Executable statements
Wend
Loop Exit and Termination Controls
● Stop Statement: Suspends or completely terminates execution at any active location in
the program. Written simply as Stop.
● Exit Statements: Forcibly interrupts and jumps out of active code structures.
○ Exit Do: Exits a Do...Loop early.
○ Exit For: Exits a For...Next loop early.
○ Exit Function / Exit Sub / Exit Property: Breaks execution out of active routines.
3. Object-Oriented Core Concepts
Classes vs. Objects
● Class: The structural blueprint or template. It defines the abstract properties, variables,
methods, and events that describe what an object can do.
● Object: An actual physical entity created in memory. It is a concrete instance of a class.
Methods: Subroutines vs. Functions
Methods are blocks of executable code mapped inside a class that carry out specific
procedures.
1. Subroutines (Sub)
Perform operations but do not return any value back to the calling routine.
Sub WriteLog(ByVal message As String)
[Link](message)
End Sub
2. Functions (Function)
Perform operations and must return a designated value back to the calling code.
Function Add(ByVal a As Integer, ByVal b As Integer) As Integer
Return a + b
End Function
Events
Events are dynamic notifications triggered by runtime environments or directly by user behavior
(e.g., clicking a button, hovering a mouse, or changing a value).
● Handles Keyword: [Link] associates a specific subroutine handler to an event using
the Handles keyword.
● Example:
Private Sub OK_Click() Handles [Link]
' Code runs when the user clicks the "OK" control
End Sub
Classes Versus Components
● Class: A software blueprint that defines the characteristics and behaviors of instances
(objects). It provides pure programmatic descriptions.
● Component: A physical object, wrapper, or control that is deployable, reusable, and
visual. Components are built on classes but are specifically designed to interact visually
and functionally with drag-and-drop toolboxes in frameworks like Visual Studio (e.g.,
textboxes, buttons).