Chapter 1: Introduction to Programming & VB
1.1 Computer Systems
Hardware (CPU, memory, storage, I/O) + Software (OS, applications). Programs are sets of instructions that tell the computer what to do.
- CPU — Central Processing Unit, the "brain"
- RAM — volatile memory, lost on shutdown
- Hard drive/SSD — persistent storage
1.2 Programs & Programming Languages
Low-level (machine language, assembly) → High-level (VB, Python, Java). Source code → Compiler/Interpreter → Machine code.
- Syntax: rules of the language
- Compiler: translates all at once
- Interpreter: translates line by line
1.3 More About Controls
Form design in Visual Studio IDE. Common controls: Button, Label, TextBox, PictureBox.
- Properties: Text, Name, Size, Location, BackColor, ForeColor, Font
- Events: Click, Load, TextChanged, MouseEnter/MouseLeave
1.4 The Programming Process
1. Analyze requirements → 2. Design UI → 3. Write code → 4. Test → 5. Debug → 6. Deploy
1.5 Visual Studio
IDE features: Solution Explorer, Properties window, Toolbox, Code Editor, Error List, Debugger.
Chapter 2: Creating Apps with VB
2.1 Problem Solving
Steps: Understand → Plan → Design UI → Code → Test
2.2 Building the Directions App
Create form, add controls, set properties, write event handlers.
2.3 Responding to Events
Event-driven programming. Private Sub btnName_Click(sender, e) Handles btnName.Click
- Event handler = method that runs when an event occurs
- The
Handleskeyword connects the handler to the control/event
2.4-2.5 Modifying Properties in Code
controlName.PropertyName = value — e.g. lblOutput.Text = "Hello"
- AutoSize: control shrinks/grows to fit content
- BorderStyle: None, FixedSingle, Fixed3D
- TextAlign: TopLeft, TopCenter, TopRight, MiddleLeft, etc.
Chapter 3: Variables & Calculations
3.1 TextBox Input
txtInput.Text returns a string. Must convert for math: CDec(txtInput.Text) or Decimal.Parse(txtInput.Text).
3.2 Variables & Data Types
Dim name As String
Dim age As Integer = 25
Dim price As Decimal = 19.99D
Dim flag As Boolean = True
| Type | Size | Values |
|---|---|---|
| Integer | 4 bytes | -2.1B to 2.1B |
| Double | 8 bytes | Floating point |
| Decimal | 16 bytes | Financial (most precise) |
| String | Variable | Text |
| Boolean | 2 bytes | True/False |
| Char | 2 bytes | Single character |
3.3 Arithmetic & Precedence
PEMDAS: Parentheses → Exponents → Multiplication/Division → Addition/Subtraction
^ Exponentiation
* Multiplication
/ Division (returns Double)
\ Integer Division
Mod Modulus (remainder)
+ Addition
- Subtraction
3.4 Type Conversion & Option Strict
Option Strict On (recommended) — forces explicit conversions. Use conversion functions:
CInt(), CDec(), CDbl(), CStr(), CBool(), Val() (returns Double from string).
Implicit conversion = narrowing (data loss possible). Explicit conversion = using conversion functions.
3.5 Formatting (ToString)
price.ToString("C") → $19.99 (currency)
num.ToString("N") → 1,234.57 (number)
num.ToString("P") → 12.34% (percent)
num.ToString("F2") → 123.46 (fixed, 2 decimals)
3.6 Class-Level Variables
Declared at the form level (before any Sub or Function), accessible from all procedures in the class. Use Private or Dim in the declarations section.
3.7 Exception Handling
Try
' Code that might cause an error
result = CDec(txtInput.Text)
Catch ex As Exception
MessageBox.Show("Invalid input: " & ex.Message)
Finally
' Runs whether error or not
End Try
Chapter 4: Making Decisions
4.1-4.2 If...Then Statements
If condition Then
' Code runs if True
End If
Relational operators: = <> < > <= >=
4.3 If...Then...Else
If score >= 70 Then
lblResult.Text = "Pass"
Else
lblResult.Text = "Fail"
End If
ElseIf for multiple conditions:
If grade >= 90 Then
letter = "A"
ElseIf grade >= 80 Then
letter = "B"
ElseIf grade >= 70 Then
letter = "C"
Else
letter = "F"
End If
4.4 Nested If
If statements inside other If statements:
If loggedIn Then
If isAdmin Then
lblMsg.Text = "Admin panel"
Else
lblMsg.Text = "User panel"
End If
End If
4.5 Logical Operators
And Both True
Or Either True
Not Reverses True/False
Xor Exactly one True
AndAlso Short-circuit AND (stops evaluating if first is False)
OrElse Short-circuit OR (stops evaluating if first is True)
4.6 Comparing Strings
Option Compare Text — case-insensitive
Option Compare Binary — case-sensitive (default)
If name.ToUpper() = "JOHN" Then
' Case-insensitive comparison
If String.Compare(str1, str2, ignoreCase:=True) = 0 Then
' Another way
4.7 Select Case
Select Case grade
Case 90 To 100
letter = "A"
Case 80 To 89
letter = "B"
Case 70 To 79
letter = "C"
Case "F", "D"
letter = Nothing
Case Else
letter = "Invalid"
End Select
4.8 Input Validation
- TryParse:
Decimal.TryParse(txtInput.Text, result)— returns True/False - Try/Catch: handle conversion errors
- IsNumeric:
If IsNumeric(txtInput.Text) Then(older approach) - Check for empty:
If txtInput.Text = "" ThenorIf String.IsNullOrEmpty(txtInput.Text) Then
📝 Practice Exam — Chapters 1-4
20 questions covering all four chapters. Select the best answer for each.
🃏 Flashcards — Chapters 1-4
Card 1 of 0
📋 Cheat Sheet — Exam 1
📦 Data Types
Integer Whole #s
Decimal Money/finance
Double Scientific
String Text
Boolean True/False
Char One char
🔢 Conversion
CInt(x) To Integer
CDec(x) To Decimal
CDbl(x) To Double
CStr(x) To String
Val(x) To Double
.TryParse() Safe conversion
➗ Arithmetic
+ Add
- Subtract
* Multiply
/ Float divide
\ Integer divide
Mod Remainder
^ Power
🔗 Relational
= Equal (NOT ==)
<> Not equal
< Less than
> Greater than
<= Less/equal
>= Greater/equal
🧩 Logical
And Both true
Or Either true
Not Reverse
Xor One true
AndAlso Short-circuit AND
OrElse Short-circuit OR
🎨 Format
.ToString("C") Currency
.ToString("N") Number
.ToString("P") Percent
.ToString("F2") Fixed 2 dec
.ToString("0.00") Custom
🔀 If/Select
If x > y Then
ElseIf x = y Then
Else : End If
Select Case x
Case 1 To 5
Case 6, 7, 8
Case Else
End Select
⚠️ Exception
Try
risky code
Catch ex As Exception
handle error
Finally
cleanup
End Try