0% found this document useful (0 votes)
105 views12 pages

CSC 231 Lecture Notes

The document provides an overview of Object-Oriented Programming (OOP) with Visual Basic, highlighting its benefits such as code reusability, data security, and maintainability, along with key concepts like classes, encapsulation, inheritance, and polymorphism. Additionally, it introduces electronic spreadsheets, detailing their functionalities, examples of software, and basic operations in Microsoft Excel, including creating, formatting, and managing workbooks and worksheets. Overall, it emphasizes the structured and efficient approach to software development and data management.

Uploaded by

yinka
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
105 views12 pages

CSC 231 Lecture Notes

The document provides an overview of Object-Oriented Programming (OOP) with Visual Basic, highlighting its benefits such as code reusability, data security, and maintainability, along with key concepts like classes, encapsulation, inheritance, and polymorphism. Additionally, it introduces electronic spreadsheets, detailing their functionalities, examples of software, and basic operations in Microsoft Excel, including creating, formatting, and managing workbooks and worksheets. Overall, it emphasizes the structured and efficient approach to software development and data management.

Uploaded by

yinka
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 12

OBJECT-ORIENTED PROGRAMMING (OOP) WITH VISUAL BASIC (VB)

1.1 What is Object-Oriented Programming (OOP)?

Object-Oriented Programming (OOP) is a programming method that organizes code into objects and classes. It
is based on real-world entities, making software development more structured, reusable, and manageable.

1.2. Benefits of OOP

OOP provides many advantages in programming, including:

 Code Reusability – You can use existing classes and objects in different programs, reducing code
duplication.
 Data Security – Encapsulation ensures that important data is protected from unauthorized access.
 Scalability and Maintainability – Code is easier to update and expand without breaking other parts.
 Better Organization – Programs are structured using logical relationships, making them easier to
understand.
 Improved Debugging – Since objects are independent, errors can be located and fixed easily.

2. KEY OOP CONCEPTS IN VISUAL BASIC (VB)

Visual Basic (VB) supports all the core principles of OOP. The four key concepts in OOP are:

i. Classes and Objects


ii. Encapsulation
iii. Inheritance
iv. Polymorphism

Let's look at each one in detail with simple examples.

2.1. Classes and Objects

A class is a blueprint or template used to create objects. It defines properties (variables) and methods (functions)
that objects will have.

An object is an instance of a class. Think of a class as a recipe and an object as the actual dish made from that
recipe.

Example: Creating a Student Class

vb
Public Class Student
Public Name As String
Public Age As Integer

' Method to display student details


Public Sub DisplayInfo()
Console.WriteLine("Student Name: " & Name & ", Age: " & Age)
End Sub
End Class
Explanation:

 The class Student has two properties: Name and Age.


 It has a method called DisplayInfo() that prints the student's details.

Creating an Object from the Class

Dim student1 As New Student()


student1.Name = "John Doe"
student1.Age = 22
student1.DisplayInfo() ' Output: Student Name: John Doe, Age: 22

Explanation:

 student1 is an object created from the Student class.


 We assign values to Name and Age, then call DisplayInfo() to print them.

2.2. Encpsulation

Encapsulation means hiding the internal details of a class while allowing controlled access through methods.
This helps protect data from accidental modification.

Example: Bank Account Class with Encapsulation

Public Class BankAccount


Private balance As Double ' Private variable, cannot be accessed directly

' Method to deposit money


Public Sub Deposit(amount As Double)
If amount > 0 Then
balance += amount
End If
End Sub

' Method to retrieve balance


Public Function GetBalance() As Double
Return balance
End Function
End Class

Explanation:

 The balance variable is private, meaning it cannot be accessed directly from outside the class.
 The method Deposit(amount As Double) allows controlled modification of balance.
 The method GetBalance() allows controlled reading of the balance.

Using the Encapsulated Class

vb
CopyEdit
Dim myAccount As New BankAccount()
myAccount.Deposit(500)
Console.WriteLine("Balance: " & myAccount.GetBalance()) ' Output: Balance: 500

Explanation:

 We create a BankAccount object.


 We deposit 500 using Deposit(), but cannot access balance directly.
 GetBalance() retrieves the current balance safely.

2.3. Inheritance

Inheritance allows a child class to inherit properties and methods from a parent class. This avoids repeating code
and enables code reuse.

Example: Animal and Dog Classes

Public Class Animal


Public Sub Speak()
Console.WriteLine("Animal makes a sound")
End Sub
End Class

Public Class Dog


Inherits Animal
End Class

Explanation:

 Animal is a parent class with a Speak() method.


 Dog is a child class that inherits from Animal.
 The Dog class does not need to redefine Speak() because it gets it from Animal.

Using the Derived Class

Dim myDog As New Dog()


myDog.Speak() ' Output: Animal makes a sound

Explanation:

 myDog is an object of Dog, but it can use the Speak() method from Animal.

2.4. Polymorphism

Polymorphism means "many forms"—a method can have different implementations in different classes. This is
useful when a child class overrides a method from the parent class.

Example: Overriding Speak() in Dog Class

Public Class Animal


Public Overridable Sub Speak()
Console.WriteLine("Animal makes a sound")
End Sub
End Class

Public Class Dog


Inherits Animal
Public Overrides Sub Speak()
Console.WriteLine("Dog barks")
End Sub
End Class

Explanation:

 The Animal class has a Speak() method.


 The Dog class overrides Speak() to provide its own version (Dog barks).

Using Polymorphism

Dim pet As New Dog()


pet.Speak() ' Output: Dog barks

Explanation:

 Although pet is still based on Animal, it calls the overridden Speak() from Dog instead.

Summary

OOP in Visual Basic provides a structured, reusable, and secure way to develop software. The key concepts are:

 Classes and Objects – Define blueprints and create instances.


 Encapsulation – Protect data and control access.
 Inheritance – Allow classes to reuse properties and methods.
 Polymorphism – Enable method flexibility.

By understanding and applying these concepts, programmers can create efficient, scalable, and maintainable
applications in Visual Basic (VB).

1. INTRODUCTION TO ELECTRONIC SPREADSHEET

An electronic spreadsheet is a digital tool that allows users to organize, store, manipulate, and analyze numerical
and textual data using a structured grid of rows and columns. It is widely used in businesses, education,
research, finance, and personal data management due to its ability to automate calculations and visualize data
efficiently. In earlier times, businesses and accountants used paper-based spreadsheets to record financial
transactions. However, with the advancement of technology, electronic spreadsheets have replaced manual
record-keeping, offering greater accuracy, speed, and convenience.

1.1. Examples of Spreadsheet Software


Several spreadsheet applications exist, with the most popular ones being:

 Microsoft Excel – The most widely used spreadsheet application.


 Google Sheets – A cloud-based spreadsheet tool with real-time collaboration features.
 LibreOffice Calc – An open-source spreadsheet program similar to Excel.
 Apple Numbers – A spreadsheet application for macOS and iOS users.
 Lotus 1-2-3 – One of the first spreadsheet applications, now obsolete.

BASICS OF MICROSOFT EXCEL

The Microsoft Excel is a spreadsheet package included in the Microsoft Office . The Microsoft
Office suite includes apps that give us the ability to create and manage every type of file we need to
work effectively at home, business, or school. The apps include Microsoft Word, Excel, Outlook,
PowerPoint, Access, OneNote, and Publisher. They are designed as an integrated package.

In Microsoft Excel the data we enter, whether it consists of numbers, text, or formulas, is stored in
a file known as a workbook. Workbooks are just like huge electronic books with pages (or sheets)
that have been organised into columns and rows. Before using Excel it is helpful to know what the
various parts and elements that make up a workbook are.
o A worksheet (or page) in a workbook contains 16,384 columns that are labelled using letters
of the alphabet. The first column in a worksheet is labelled column A, while the last is labelled XFD
o A worksheet (or page) in a workbook contains 1,048,576 rows that are labelled using
numbers from 1 to 1,048,576.
o The area of intersection of rows and columns are called cells. We enter our data into these
cells. Each cell in a worksheet can hold up to 32,767 characters – although it would be unrealistic
to ever push it this far. Cells are referred to by their column and row labels. For example, the cell
C11 (intersection of Column C and Row 11)– this reference is known as the cell
address and is most important as it is frequently used in commands and formulas.
o When we start typing something, we want it to appear somewhere in the
worksheet. As a consequence when the Status Bar shows Ready mode, at least one
cell in the worksheet will be highlighted – this is known as the active cell. In a case
if, the active cell is cell A1 – notice that the column label and the row label also
appears coloured to indicate the active cell. We can have more than one active cell –
known as a range
o A workbook is made up of pages known as worksheets. We can have as many
sheets in a workbook as our computer resources can accommodate. As a default, a
new blank workbook normally has 3 worksheets labelled Sheet1, Sheet2, and Sheet3.
o The Insert Worksheet button will insert another worksheet into the current workbook.

Create and Format Workbooks

1. To create a new workbook


1. Do any of the following:
a. If Excel is not running, start Excel, and then on the Start screen,
double-click Blank workbook.
b. If Excel is already running, click the File tab of the ribbon, click New to
display the New page of the Backstage view, and then double click Blank
workbook.
c. If Excel is already running, press Ctrl+N.
2. Display the Backstage view, and then click Save As.
3. On the Save As page of the Backstage view, click the folder where we want to
save the workbook.
4. In the Save As dialog box, in the File name box, enter a new name for
workbook.To save the file in a different format, in the Save as type list, click a
new file type. If necessary, use the navigation controls to move to a new folder.
5. Click Save.
Or
a. Press F12.
b. In the Save As dialog box, in the File name box, enter a
new name for the workbook.
c. To save the file in a different format, in the Save as type list, click a new file type.
d. If necessary, use the navigation controls to move to a new folder.
e. Click Save.

2. To open an existing workbook


a. Display the Backstage view, and then click Open.
b. On the Open page of the Backstage view, perform any of these actions:
o Click a file in the Recent list.
o Click another location in the navigation list and select the file.
o Click the Browse button, and then use the Open dialog box to find the
file we want to open, click the file, and click Open.
3. To close a workbook
Do either of the following:
a. Display the Backstage view, and then click Close.
b. Or, Press Ctrl+W.
4. Preview and Print a Workbook:
Click the File tab and select Print.
5. Recover an Unsaved Workbook:
Restart Excel. If a workbook can be recovered, it will appear in the
Document Recovery pane. Or, click the File tab, click Recover unsaved workbooks
to open the pane, and select a workbook from the pane.

View and Manage Worksheets:

1. Inserting and deleting worksheets


Once we‘ve decided on a structure for our workbook, we may find that there are
some worksheets that can be deleted. Alternatively, we may find that we need
additional blank worksheets inserted. However, remember that deletion of
worksheets is permanent and can‘t be undone using Undo, so always save the
workbook before making these changes.

To insert a new worksheet into a workbook:

Click on the New Sheet icon to the right of the worksheet tabs

To delete a worksheet from a workbook:

Right click on the worksheet tab, then select Delete.

2. Copying a worksheet
Just as we can copy the contents of cells and ranges within a worksheet, we can
duplicate worksheets within a workbook. This technique is ideal for replicating
layouts. For example, if we have a budget workbook that contains data for several
departments, we can create a worksheet for the first department and then copy it to
create identical worksheets for other departments.

To copy a worksheet:

a. Right click on the worksheet to copy, then select Move or Copy


b. Click on Create a copy so it appears ticked
c. Click on [OK]

3. Renaming a worksheet
By default, Excel names worksheets as Sheet1, Sheet2, Sheet3, etc. These names are
fine if we are not planning to share the workbook, but changing these to something
more relevant makes it much easier to understand the purpose of a worksheet. We
can also adjust the horizontal scroll bar to make room for longer, more meaningful
worksheet names.

To rename a worksheet:

a. Double click on the current name on the worksheet tab.


b. Type the new name and press enter.
4. Moving or copying a sheet to another workbook
We can copy worksheets to other workbooks as required. For example, we might
need to keep records for six different divisions – rather than send each division the
entire set of records, we can copy their worksheet to another workbook and send
them their data only. If worksheets exist in the other workbook, we will need to
determine the order in which to place the copied worksheet.

To copy a sheet to another workbook:

a. Right click on the worksheet tab, then click on Move or Copy


b. Select either (new book) or the name of another workbook in To book
c. Tick Create a copy, then click on [OK]

5. Changing worksheet tab colours


To make it easier for us to distinguish between worksheets, Excel enables us to
change the colours of worksheet tabs. This allows us, for example, to quickly
distinguish between different financial years, departments or months. The active
sheet appears as underlined in a gradient version of the selected colour, while
inactive tabs will display a solid colour background.
To change the colour of a worksheet tab:

a. Right click on the worksheet tab to display the shortcut menu.


b. Point to Tab colour to display a palette of colour options
c. Click on the desired color

6. Grouping worksheets
Worksheet grouping enables us to make the same change at once to all selected
worksheets. This feature is useful in situations where our worksheets have identical
layouts or text. For example, if we want to format the heading for multiple
worksheets, we simply group the worksheets, make a change to one worksheet and
the other worksheets will reflect the change also.

To group worksheet tabs:

1. Click on the first worksheet tab


2. Hold down the shift
7. To delete a worksheet
a. Right-click the sheet tab of the worksheet we want to delete, and then click Delete.
b. If Excel displays a confirmation dialog box, click Delete.
8. To change row height

a. Select the row headers for the rows we want to resize.


b. Point to the bottom border of a selected row header.
c. When the pointer changes to a double-headed vertical arrow, drag the
border until the row is the height we want.
Or
a. Select the row headers for the rows we want to resize.
b. Right-click any of the selected row headers, and then click Row Height.
c. In the Row Height dialog box, enter a new height for the selected rows.
d. Click OK.

2. FEATURES OF AN ELECTRONIC SPREADSHEET


Modern spreadsheets provide a variety of powerful features that allow users to manage and
analyze data effectively.
2.1. Definitions of Terms in an Electronic Spreadsheet

i. Row
A row is a horizontal arrangement of cells in a spreadsheet, identified by numbers (e.g.,
1, 2, 3…).
ii. Column
A column is a vertical arrangement of cells in a spreadsheet, identified by letters (e.g., A,
B, C…).
iii. Cell
A cell is the intersection of a row and a column, identified by a cell reference (e.g., A1,
B5). It is the basic unit where data is entered.
iv. Range
A range is a group of two or more selected cells in a spreadsheet. It can be contiguous
(e.g., A1:A5) or non-contiguous (e.g., A1:A5, C1:C5).
v. Value
A value is a numerical or textual entry in a cell. It can be a number, date, time, or text.
vi. Function
A function is a predefined formula in a spreadsheet that performs a specific calculation
(e.g., SUM(A1:A5), AVERAGE(B1:B10)).
vii. Formula
A formula is a user-defined expression that performs calculations using values, cell
references, and functions. It starts with an equal sign (=) (e.g., =A1+B1, =SUM(C1:C10)).

2.2. Data Types in Spreadsheet Cells


 Numbers: Used for calculations (e.g., 100, 250.5).
 Text (Labels): Non-numeric characters for descriptions (e.g., "Total Sales").
 Formulas: Mathematical expressions for calculations (e.g., =A1+B1).
 Functions: Predefined formulas for common tasks (e.g., =SUM(A1:A10)).
2.3. Formulas and Functions
 Formulas are user-defined calculations using mathematical operators (+, -, *, /).
o Example: =A1+B1 adds values in cells A1 and B1.
 Functions are built-in formulas for automatic calculations.
o Example: =SUM(A1:A5) calculates the sum of values from A1 to A5.
2.4. Formatting Features
 Font Styles: Bold, Italic, Underline.
 Cell Formatting: Change background color, font size, and number formatting.
 Conditional Formatting: Automatically change cell appearance based on conditions.
2.5. Charts and Graphs
Spreadsheets allow users to create visual representations of data such as:
 Bar Charts – Used to compare categories.
 Pie Charts – Displays proportions of a whole.
 Line Graphs – Shows trends over time.
 Scatter Plots – Illustrates relationships between variables.
2.6. Data Sorting and Filtering
 Sorting: Arrange data in ascending or descending order.
 Filtering: Display only specific data based on criteria.
3. BASIC OPERATIONS IN AN ELECTRONIC SPREADSHEET
3.1. Entering and Editing Data
 Click a cell and type to enter data.
 Press Enter to move down to the next row.
 Press Tab to move to the next column.
3.2. Performing Basic Calculations
 Addition: =A1 + B1
 Subtraction: =A1 - B1
 Multiplication: =A1 * B1
 Division: =A1 / B1
3.3. Using Common Functions

Function Description Example


SUM Adds values in a range =SUM(A1:A10)
AVERAGE Finds the average =AVERAGE(B1:B10)
MAX Finds the highest value =MAX(C1:C10)
MIN Finds the lowest value =MIN(D1:D10)
IF Logical function =IF(A1>50, "Pass", "Fail")
COUNT Counts cells with numbers =COUNT(A1:A10)

4. SHORTCUT KEYS USED IN ELECTRONIC SPREADSHEETS

Shortcut Key Function


Ctrl + N Create a new spreadsheet
Ctrl + O Open an existing spreadsheet
Ctrl + S Save the current spreadsheet
Ctrl + Z Undo last action
Ctrl + Y Redo last undone action
Ctrl + C Copy selected cell(s)
Ctrl + X Cut selected cell(s)
Ctrl + V Paste copied/cut content
Ctrl + P Print the spreadsheet
Ctrl + B Bold selected text
Ctrl + I Italicize selected text
Ctrl + U Underline selected text
Ctrl + Shift + + Insert a new row/column
Ctrl + - Delete a row/column
Ctrl + Arrow Key Move quickly across data
Ctrl + Space Select entire column
Shift + Space Select entire row
Alt + Enter Insert a new line in a cell

5. APPLICATIONS OF ELECTRONIC SPREADSHEETS

Field Application
Business Financial analysis, payroll processing, budgeting
Education Student grading, attendance records
Research Data collection, statistical analysis
Engineering Simulation models, complex calculations
Healthcare Patient records, drug inventory
Banking Loan calculations, interest computation

Electronic spreadsheets are essential tools in modern computing for managing, analyzing, and
presenting data. They provide:
 User-friendly interfaces
 Powerful computational abilities
 Advanced visualization tools
 Automation for repetitive tasks
By mastering spreadsheets, users can improve efficiency in data management and decision-
making processes.

You might also like