Week 1 & 2: Rules For Naming Valid VB Variables
Week 1 & 2: 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.
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.
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.
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
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
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.
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:
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. 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
Table of Content
mathScore = Val(txtMath.Text)
scienceScore = Val(txtScience.Text)
englishScore = Val(txtEnglish.Text)
' Calculate total and average
averageScore = totalScore / 3
grade = "A"
grade = "B"
grade = "C"
grade = "D"
Else
grade = "F"
End If
End Sub
2. HOTEL RESERVATION SYSTEM FORM
Table of Content
roomType = cmbRoomType.Text
nights = Val(txtNights.Text)
isAvailable = True
isAvailable = False
Else
Exit Sub
End If
If isAvailable Then
Else
End If
End Sub