0% found this document useful (0 votes)
16 views10 pages

Week 1 & 2: Rules For Naming Valid VB Variables

The document outlines the rules for naming valid VB variables, highlighting the importance of meaningful names and the distinction between local and global variables. It also explains how to declare variables in VB 6.0 and provides algorithms and flowcharts for basic programming tasks. Additionally, it covers Object-Oriented Programming principles using real-world examples and includes practical applications like a student grade calculator and a hotel reservation system.

Uploaded by

Ekuma Emmanuel
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)
16 views10 pages

Week 1 & 2: Rules For Naming Valid VB Variables

The document outlines the rules for naming valid VB variables, highlighting the importance of meaningful names and the distinction between local and global variables. It also explains how to declare variables in VB 6.0 and provides algorithms and flowcharts for basic programming tasks. Additionally, it covers Object-Oriented Programming principles using real-world examples and includes practical applications like a student grade calculator and a hotel reservation system.

Uploaded by

Ekuma Emmanuel
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/ 10

WEEK 1 & 2

1. Rules for Naming Valid VB Variables

1. A variable name must not contain spaces or special characters like @, #, !, etc. It can
have numbers, but not at the beginning.
2. The variable name must start with a letter (A–Z).
3. Variable names are not case sensitive, so Age and age are considered the same.
4. You should not use a VB keyword or reserved word (like If, Then, End, etc.) as a
variable name.
5. Use simple and meaningful names, so anyone reading your code can understand what
the variable is for.

Table Showing 10 Valid and 10 Invalid VB Variable Names

Valid Variable Names Invalid Variable Names


studentName 1stStudent
Age full name
score1 @marks
totalMarks End
subjectList student-name
isPassed *grade
noOfSubjects full.name
amountPaid Then
classAverage class average
total_Amount !result

Differences Between Local and Global Variables in VB 6.0

1. A global variable is declared at the top of your code, outside all blocks, and can be
used anywhere in the program.
2. A local variable is declared and used inside a procedure, function, or event like a
button click. It works only in that specific part of the code.

4. How to Declare Variables in VB 6.0

To declare a variable in VB6, we use the Dim keyword. This keyword helps to tell the
program that we are creating a new variable. After using Dim, you give the variable a name,
and then you tell the program what kind of data the variable will store. The type of data could
be a String (for text), an Integer (for whole numbers), a Double (for decimal numbers), or a
Boolean (for true or false values). For example, if we want to store a student's name, we use a
String type. If we want to store the student's age, we use an Integer. To store whether the
student passed the exam, we use a Boolean (True or False). And if we want to store the
student’s exam score, we use a Double type because scores often have decimal points.

' Declaring variables


Dim studentName As String
Dim age As Integer
Dim isPassed As Boolean
Dim examScore As Double

' Assigning values to the variables


studentName = "John"
age = 20
isPassed = True
examScore = 85.5

' Displaying the values (optional)


MsgBox "Student Name: " & studentName
MsgBox "Age: " & age
MsgBox "Passed: " & isPassed
MsgBox "Exam Score: " & examScore
WEEK 3 & 4

Question 1: Algorithm and Flowchart to Check if a Number is Positive,


Negative, or Zero

Algorithm

1. Start
2. Enter a number and store it in a variable called num
3. If num is greater than 0, display "The number is positive"
4. If num is less than 0, display "The number is negative"
5. If num is equal to 0, display "The number is zero"
6. Stop

Flowchart

flowchart to check if a number is positive, negative, or zero.

Question 2: Algorithm and Flowchart to Calculate the Square of a Number.

Algorithm

1. Start
2. Ask the user to enter a number and save it in a variable called num
3. Calculate the square of the number by using this formula:
square = num × num
4. Show or return the value of square
5. Stop
Flowchart to Calculate the Square of a Number.
WEEK 5 & 6

1. Using a Real-World Object as an OOP Object: The Car Example

In the world of programming, Object-Oriented Programming (OOP) helps us understand real-


life things in terms of objects. A real-world object, like a car, can be described as an OOP
object. In simple terms, an object in OOP is like something you see or use every day, and it
has certain characteristics and can perform certain actions.

Using Car as an example.

Properties (What the Car Has)

Just like a real car has different features, an OOP object also has things it “owns” or “has.”
These are called properties or attributes. For a car, we can say it has the following properties:

1. Color – This tells us what color the car is, like red, blue, or black.
2. Model – The model of the car refers to its type, like a Toyota Corolla or Honda Civic.
3. Speed – This property tells us how fast the car is going.

So, in OOP, we can say the car’s properties are its color, model, and speed. These help us
understand what the car is like.

Methods (What the Car Can Do)

Now, just like how a real car can perform actions, an OOP object can also do things through
its methods. A method is basically an action that the object can perform. For our car, the
following are some examples of methods:

1. StartEngine() – This method turns on the car’s engine, so it can move.


2. Accelerate() – This method makes the car go faster, increasing its speed.
3. Brake() – This method helps the car slow down or stop.

So, when we think of the car in terms of OOP, it can perform actions such as starting its
engine, speeding up, or stopping.

2. The Four Main OOP Principles Explained

2. Inheritance

Inheritance in OOP allows a new object (child) to inherit characteristics (properties and
methods) from an existing object (parent). It’s like the child gets features from their parent.

Real-world example:

A child inheriting traits from their parents, like eye color or height. In programming, you can
create a new object, like a "SportsCar", and it can inherit properties and methods from the
general "Car" object, such as speed and color. The SportsCar is a type of car, but it also has
special features like higher speed.
4. Polymorphism

Polymorphism means that one method or action can work in different ways depending on the
object that uses it. It's like the same word or action behaving differently in different
situations.

Real-world example:

Using a dog as example, a dog makes a barking sound, a cat makes a meowing sound, and a
bell makes a ringing sound. Even though they all make a sound, each one makes a different
kind of sound. In programming, a method like makeSound() can behave differently, such as
making a dog bark, a cat meow, or a bell ring, depending on which object calls it.

4. Abstraction

Abstraction is the concept of hiding the complex details and showing only the essential
features of an object. It helps simplify things by focusing only on what’s important.

Real-world example:

When you drive a car, you only need to use the steering wheel, pedals, and gear to control it.
You don’t need to know how the engine works, or how the brakes are designed inside. The
complex parts are hidden from you, and you only interact with the important and simple
controls. That’s abstraction – showing only the necessary parts while hiding the complexity.
WEEK 7 & 8

1. STUDENT GRADE CALCULATOR

Table of Content

S/N Object Propert Setting


y

1 Form Name frmGradeCalculator

2 TextBox Name txtMath

3 TextBox Name txtScience

4 TextBox Name txtEnglish

5 Label Name lblTotal

6 Label Name lblAverage

7 Label Name lblGrade

8 CommandButton Name cmdCalculate

Caption Calculate Grade

Private Sub cmdCalculate_Click()

Dim mathScore As Integer

Dim scienceScore As Integer

Dim englishScore As Integer

Dim totalScore As Integer

Dim averageScore As Single

Dim grade As String

' Get scores from textboxes

mathScore = Val(txtMath.Text)

scienceScore = Val(txtScience.Text)

englishScore = Val(txtEnglish.Text)
' Calculate total and average

totalScore = mathScore + scienceScore + englishScore

averageScore = totalScore / 3

' Determine grade

If averageScore >= 90 Then

grade = "A"

ElseIf averageScore >= 80 Then

grade = "B"

ElseIf averageScore >= 70 Then

grade = "C"

ElseIf averageScore >= 60 Then

grade = "D"

Else

grade = "F"

End If

' Display results

lblTotal.Caption = "Total: " & totalScore

lblAverage.Caption = "Average: " & Format(averageScore, "0.00")

lblGrade.Caption = "Grade: " & grade

End Sub
2. HOTEL RESERVATION SYSTEM FORM

Table of Content

S/ Object Property Setting


N

1 Form Name frmHotelReservation

2 ComboBox Name cmbRoomType

Items Standard, Deluxe, Suite

3 TextBox Name txtNights

4 Label Name lblAvailability

5 CommandButton Name cmdReserve

Caption Check Availability & Reserve

Private Sub cmdReserve_Click()

Dim roomType As String

Dim nights As Integer

Dim isAvailable As Boolean

roomType = cmbRoomType.Text

nights = Val(txtNights.Text)

' Simulate room availability check

If roomType = "Standard" Then

isAvailable = True

ElseIf roomType = "Deluxe" Then

isAvailable = False

ElseIf roomType = "Suite" Then


isAvailable = True

Else

lblAvailability.Caption = "Please select a valid room type."

Exit Sub

End If

' Display availability message

If isAvailable Then

lblAvailability.Caption = "Room is available. Reservation successful!"

Else

lblAvailability.Caption = "Sorry, selected room is not available."

End If

End Sub

You might also like