Programming Fundamentals
Programming Fundamentals
INTRODUCTION
Programming is the process of creating a set of instructions that a computer can follow to
perform specific tasks. The process of designing a program is referred to as algorithm design
Computers do not understand human languages, so programmers use special languages
called programming languages to communicate with them. Programming is essential because
it allows us to create software applications, automate tasks, and solve real-world problems.
By learning programming, one can develop websites, mobile applications, games, and even
artificial intelligence systems.
Programming Languages
Programming languages are special languages that programmers use to write instructions for
computers. Some popular programming languages include Python, Java, C++, C, BASIC, Pascal,
COBOL and JavaScript.
Computer Programming
Computer programming is the act of writing, testing, and maintaining computer programs. It
involves designing solutions to problems and then translating those solutions into code that
a computer can execute.
Source Code
Source code is the original code written by a programmer in a programming language before
it is converted into machine-readable form. For example, a Python program written by a
programmer is considered source code.
Object Code
Object code is the machine-readable version of a program, generated after the source code
has been compiled. This is the code that the computer understands and executes.
AJ-KALEMA 1
Assembler
An assembler is a tool that converts assembly language programs into machine code.
Assembly language is a low-level language that is easier to understand than pure machine
code.
Interpreter
An interpreter is a program that reads and executes source code line by line. Languages like
Python and JavaScript use interpreters, which means they do not need to be fully compiled
before running.
Compiler
A compiler is a program that converts the entire source code into object code before the
program runs. Languages like C and Java use compilers, which makes them faster than
interpreted languages.
1. LOW-LEVEL LANGUAGES
Low-level languages are programming languages that are close to machine code and provide
little abstraction from the computer's hardware. They are difficult for humans to read and
AJ-KALEMA 2
write but are efficient for computer processing. They include machine language and
assembly language.
ADVANTAGES DISADVANTAGES
• Hard to read and write
• Very fast because the computer does not
• Not portable (specific to a particular
need translation.
type of computer hardware).
• Uses minimal system resources.
• Debugging is extremely difficult.
2. HIGH-LEVEL LANGUAGES
High-level languages are programming languages that are easier to read, write, and
understand because they use human-friendly syntax. They need to be translated into machine
code before execution. These languages use English-like words and symbols, making them
easier to learn and write.
AJ-KALEMA 3
a) Third Generation Languages (3GL)
These include languages like C, C++, Java, and Python. They are structured and
procedural, making them easier to use than low-level languages. Requires a compiler
or interpreter to convert code into machine language.
d) Object-Oriented Languages
These languages focus on objects rather than procedures. In object Oriented
Programing (OOP), a program consists of several objects that interact by sending
messages to each other’s. These objects are linked together through a method known
as association to create a complete program. Examples include Java, C++, and Python.
AJ-KALEMA 4
Benefits Limitations
• Easier to learn and use than low-level • Programs may run slower than low-
languages. level languages.
• Portable (can run on different types of • They do not give full control over
computers). system hardware.
• Faster development because of simple • Dependence on compilers or
syntax and built-in functions. interpreters to translate code.
• Easier debugging and maintenance.
1. Problem Definition
Problem definition is the first step and most important phase of program
development life cycle (PDLC). It involves clearly understanding and describing the
problem than needs to be solved before writing any code. A well-defined problem
ensures that the final program meets user requirements and functions correctly.
2. Algorithm Design
An algorithm is the process of creating a step-by-step procedure to solve the problem
before writing actual code. It acts as a blueprint that guides programmers on how to
structure their programs. The solution to the problem is expressed using flowcharts,
pseudocode or Structured English statements.
Using Pseudocode:
AJ-KALEMA 5
Program: Calculating the average of Program: Calculating area of a circle
three numbers BEGIN
START SET as constant PI=3.14
1. Get three numbers from the PRINT “Enter Radius”
user READ radius
2. Add the three numbers Area=PI*radius
3. Divide the sum by 3 to get the PRINT area
average END
4. Display the average
END
3. Program Coding
This involves writing the actual program using a programming language to create a
computer program. This step now coverts an algorithm into a form that a computer
can understand and execute. Most of the high-level languages have common features
as reserved words, operators, identifiers and variables.
❖ Reserved words
Reserved words, also known as Keywords, are special words that have a fixed
meaning in a programming language and can not be used as variable name,
function names or identifiers. These words are predefined and serve specific
function in coding. Examples; for, if, else, while and do.
❖ Identifiers
an identifier is the name given to variable, functions, classes, and other
elements in a program. It helps programmers’ reference and use these
elements in their code.
❖ Operators
An operator is a symbol or keyword used in programming to perform
operations on variables and values. Operators allow a programmer to
manipulate data and perform calculations. Here are types of operators;
1. Arithmetic operators
AJ-KALEMA 6
These operators perform mathematical operations such as addition,
subtraction, multiplication and division.
2. Assignment operators
These operators are used to assign values to variables.
Operators Example Equivalent To
= x=5 x=5
+= x += 3 x=x+3
-= x -= 2 x=x–3
*= x *= 4 x=x*3
/= x /= 2 x=x/3
%= x %= 3 x=x%3
4. Logical operators
These operators combine multiple conditions and return True or False.
AJ-KALEMA 7
Return True if both
and (5 > 3) and (10 > 5) True
conditions are true
Return True if at least
Or (5 > 3) or (10 < 5) True
one conditions is true
not Reverses the condition Not (5 > 3) False
❖ Variables
A variable is a name given to a memory location used to store data in a
problem. The value of variable can change during program execution.
AJ-KALEMA 8
• Efficiency: Uses minimal system resources.
• Readability: Easy for others to understand and modify.
• Maintainability: Can be updated and improved easily.
• Portability: Can run on different systems without modification.
Example: If Student is a class, then s is one student (object) created from that class.
AJ-KALEMA 9
3. Method
A method is a block of code that performs an action. It is written inside a class and
define the behavior or function to be performed by an object to manipulate data. In
VB.NET, a method can be a Sub (no return value) or a Function (returns a value).
Methods allow you to group code that does a specific task.
4. Variable
A variable is used to store data. It must be declared with a data type.
AJ-KALEMA 10
Comment Notes in the code for explanation ' This is a comment
🔹 2. Standard Toolbar
The Standard Toolbar is usually located just below the Menu Bar. It contains icons
(buttons) that give quick access to commonly used commands.
🔸 Common Buttons on the Standard Toolbar:
Icon/Button Function
New Project Create a new project
AJ-KALEMA 11
Redo Redo the undone action
📘 Forms in VB.NET
A Form is a window or screen in a VB.NET application where users can interact with
the program. It is part of a Graphical User Interface (GUI) and can contain controls
like buttons, labels, textboxes, etc. Think of a form like a blank sheet where you can
place tools (controls) for your program.
🔸 Types of Forms
1. Main Form – The first window that appears when the program runs.
2. Child Form – Additional forms that can be opened from the main form.
🔹 Creating a Form in VB.NET
When you create a new Windows Forms Application in Visual Studio, it automatically
includes a default form called Form1.vb. You can add more forms using:
Project > Add Windows Form...
🔹 Adding Controls to a Form
You can drag and drop controls (like buttons, labels, and textboxes) onto the form
using the Toolbox.
Example controls:
• Label – to display text
• Button – to perform an action when clicked
• TextBox – to allow user input
🔹 Writing Code for a Form
You can double-click on any control to write event-handling code, like when a
button is clicked.
AJ-KALEMA 12
Showing or Hiding a Form
🧰 Toolbox in VB.NET
The Toolbox in VB.NET is a panel that contains a list of controls (tools) you can use
to design your form. You drag and drop items from the Toolbox onto a Form to build
AJ-KALEMA 13
5. Double-click the control to write code for its event (e.g., Button Click).
AJ-KALEMA 14
7. Running the Program
Click Start or press F5 to compile and run your program.
Errors will be shown in the Error List window.
💾 Saving a VB.NET Project
Saving means storing your work (forms, code, settings) so that you can open and
continue your project later. This prevents loss of your work.
🔸 Steps to Save a VB.NET Project
📝 When you create a new project:
1. Go to File > New > Project.
2. Choose Windows Forms App (.NET Framework).
3. Give your project a Name (e.g., "MyFirstApp").
4. Choose a Location where you want to save it on your computer.
5. Click Create.
💾 To save your work while editing:
• Click File > Save All
OR
• Press Ctrl + Shift + S on your keyboard
OR
• Click the Save All icon on the toolbar (looks like two floppy disks )
This saves:
• The current form (e.g., Form1.vb)
• The code file
• The entire project structure
🔸 What Gets Saved?
When you save a VB.NET project, these main parts are stored:
File/Folder Purpose
.sln file The solution file that opens the whole project
Form1.vb The form's design and code
bin and obj folders Contain compiled files (automatically created)
Project Folder All your project files are saved here
AJ-KALEMA 15
📂 Opening an Existing VB.NET Project
Opening an existing project means loading a previously saved VB.NET project so
you can continue working on it or run it again.
🔸 Steps to Open an Existing Project in Visual Studio
1. Start Visual Studio
o Double-click the Visual Studio icon on your desktop or search for it in
the Start menu.
2. Click on "Open a project or solution"
o On the start screen, click: Open a project or solution
3. Find your project folder
o Navigate to the folder where you saved your project.
4. Open the solution file (.sln)
o Look for a file with the extension .sln (e.g., MyFirstApp.sln).
o Select it and click Open.
5. Project Loads in Visual Studio
o You will see the Form, Solution Explorer, and your code.
o You can now edit or run your project.
➕ Adding New Forms in VB.NET
A Form is a window or screen in your application where users can interact.
You can add multiple forms to your project to create different windows or dialogs.
🔸 Why Add New Forms?
• To create different screens (e.g., a Login form, Settings form)
• To organize your program better
• To allow multiple windows in your app
🔹 How to Add a New Form
1. Open your project in Visual Studio.
2. Go to the Menu Bar
Click:
3. Project > Add Windows Form...
4. Add New Item Window Appears
o Select Windows Form from the list.
o Give the form a name (e.g., Form2.vb).
AJ-KALEMA 16
o Click Add.
5. New Form Opens
o You will see a blank form design window.
o You can add controls (buttons, labels, etc.) to this form.
AJ-KALEMA 17
2️⃣ Named Constant
A named constant means you give the constant a specific name so you can use it
in your code instead of the actual value.
These are used when you have fixed messages or names in your program.
4️⃣ Numeric Constants
Numeric constants hold numbers (integers, decimals) that remain the same.
Use numeric constants for fixed numbers like mathematical values, limits, or
counts.
AJ-KALEMA 18
Module-Level Accessible to all procedures within the Declared at the top
Scope same module (form or class). of a form or class
Public Scope Accessible from any module or form in the Declared as Public
(Global) entire project. in a module
🔹 Examples of Declarations and Scope
Local Variable (Local Scope)
Sub ShowMessege()
Dim message As String = “Hello” ‘Only accessible inside ShowMessage
MsgBox(message)
End Sub
Sub ShowCounter()
MsgBox(“Count:”& counter)
End Sub
End Class
In a module file:
userName can be accessed from anywhere in the project.
AJ-KALEMA 19
📦 User-Defined Data Types in VB.NET
Structure
Dim StudentID As Integer
Dim Name As String
Dim Age As Integer
Dim Grade As String
End Structure
You can now use stud to store all student details together.
📝 Summary Table
Concept Description Example
User-Defined Data A custom structure holding Structure Student ... End
Type related data Structure
Fields Variables inside the structure StudentID, Name, Age
Instance Variable of the new data type Dim stud As Student
AJ-KALEMA 20
🔸 Common Suffixes and Their Data Types
Suffix Data Type Example Meaning
D Double Dim x = 10.5D Treats 10.5 as Double
F Single Dim y = 5.5F Treats 5.5 as Single (float)
@ Decimal Dim z = 100@ Treats 100 as Decimal
L Long Dim n = 12345L Treats 12345 as Long integer
& Long Dim m = 12345& Also Long integer
% Integer Dim i = 100% Treats 100 as Integer
! Single Dim s = 3.14! Treats 3.14 as Single
🔹 Examples of Using Suffixes
➕➖ VB.NET Operators
Operators are symbols or keywords used to perform operations on variables and
values.
For example: addition, comparison, or checking conditions.
🔸 Categories of Operators in VB.NET
Category Description Example
Arithmetic Operators Perform math calculations +, -, *, /
Comparison Operators Compare values and return True or False =, <>, <, >
Logical Operators Combine multiple conditions (True/False And, Or,
logic) Not
Assignment Operator Assigns a value to a variable =
AJ-KALEMA 21
Concatenation Joins (adds) strings together &
Operator
1️⃣ Arithmetic Operators
Operator Meaning Example Result
+ Addition 5+3 8
- Subtraction 10 - 4 6
* Multiplication 6*2 12
/ Division 9/3 3.0
\ Integer Division 10 \ 3 3
Mod Remainder 10 Mod 3 1
^ Exponentiation 2^3 8
AJ-KALEMA 22
5️⃣ Concatenation Operator (Strings)
Operator Meaning Example Result
& Joins strings "Hello" & " " & "World" "Hello World"
AJ-KALEMA 23
Mid(str,
start, Extracts part of string Mid("Computer", 2, 3) "omp"
length)
Removes spaces from both
Trim(str) Trim(" Hello ") "Hello"
ends
AJ-KALEMA 24
🔸 Example 1: Formatting Numbers
AJ-KALEMA 25
🔸 Common Conversion Methods:
Method Description Example Output
CStr() Converts any value to String CStr(123) "123"
.ToString() Method available on all numbers 123.ToString() "123"
🔸 Example:
🔸 Key Points:
• Code runs from top to bottom.
• Each line is executed once.
• There are no decisions or loops involved.
AJ-KALEMA 26
🔸 Example:
AJ-KALEMA 27
2️⃣ If...Then...Else
Used when you want to choose between two options.
3️⃣ If...ElseIf...Else
Used when you have more than two choices.
✅ The program checks conditions one by one and runs the first one that is True.
4️⃣ Select Case
Used when testing one variable with many possible values.
AJ-KALEMA 28
✅ The program checks the value of day and shows the correct message.
📌 Summary Table
Statement Type Used For Example Keyword
If...Then Run only if condition is True If condition Then
If...Then...Else Choose between 2 options Else
If...ElseIf...Else Choose from many options ElseIf
Select Case Many values of one variable Select Case
For i As Integer = 1 To 5
MsgBox(“Clap number: ” & i)
Next
Dim i As Integer = 1
Do While I <= 3
MsgBox( “Number is:” & i)
I +=1
Loop
AJ-KALEMA 29
3️⃣ Do...Loop While
This version runs the code first, then checks the condition.
Dim i As Integer = 1
Do
MsgBox( “I = ” & i)
I +=1
Loop While i<= 3
✅ It works like Do While, but it always runs at least once, even if the condition is False at
the start.
4️⃣ Do Until...Loop
This loop runs until the condition becomes True.
Dim i As Integer = 1
Do Until i > 3
MsgBox( “i is:” & i)
I +=1
Loop
AJ-KALEMA 30