0% found this document useful (0 votes)
12 views51 pages

Chapter 3

Uploaded by

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

Chapter 3

Uploaded by

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

CHAPTER 3:

PROGRAM
DESIGN AND
CODING
DFP40233 Visual Basic Programming
COURSE LEARNING OUTCOME
CLO1:
Construct the visual basic program by using .NET frameworks in developing
windows Application. (P4,PLO3)

CLO3:
Demonstrate effective leadership with peer in developing Visual Basic programs.
(A3,PLO5)
COMMON PROGRAMMING
TECHNIQUE
Syntax
Data Types
Global, form-level and local variable
Variables
Option Explicit
Constant
Decision Making Statements
Operators
Continue and Exit Statements
Array
SYNTAX
Syntax which represent a line, is a For example:
command statement of a programmer to  Dim a As String = “Hello”
the application so it can execute the  Dim A As String = “Hello”
order
A and a has different reference
In VB.NET, a syntax consist of a line
without any symbol at the end of the
statement
Thus, optimizing VB.NET code is
limited
It’s a case sensitive syntax so uppercase
and lowercase character matters
DATA TYPES
Boolean (Depends on platform) Object (4 bytes [32bit], 8 bytes [64bit])
Byte (1 byte, Unsigned) Sbyte (1 byte, Signed)
Char (2 bytes, Unsigned) Short (2 bytes, Signed)
Date (8 bytes ) Single (4 bytes)
Decimal (16 bytes) String (Depends on platform)
Double (8 bytes) Uinteger (4 bytes, Unsigned)
Integer (4 bytes) Ulong (8 bytes, Unsigned)

Long (8 bytes) User-Defined (Depends on platform)


Ushort (2 bytes, Unsigned)
VARIABLES
It is a reference identification with a For example
space holding a value  Dim myVariable As Integer

In VB.NET it start with DIM


Followed by the reference id(variable
name)
Finished by AS <Data Type>
End with no symbol
Recommended to follow naming
convention to make it standardize.
VARIABLES CONT
Type Example
Integral Types SByte, Byte, Short, UShort, Integer, UInteger, Long, ULong and Char
Floating Point Types Single and Double
Decimal Types Decimal
Boolean Types True or False values, as assigned
Date Types Date
VARIABLES (CONT)
Local Form-Level Global
Represent as a parameter or Declared within a form Technically VB.NET doesn’t
declared within of a sub or have global variable but a
function procedure workaround is to use singleton,
or use public on variables that
need to be shared (bad practice!)
Sub CalculatePay(ByRef hours As Double, ByRef Public Class Form1 Public NotInheritable Class MyVariables
wage As Decimal) Dim firstValue As Boolean Private Shared Input1 As String
Dim pay As Double pay = hours * wage
End Class Public Shared Sub
Console.WriteLine("Total Pay: {0:C}",
pay) SetDefaultOnInputTwo()
End Sub Input2 = "World"
End Sub
End Class
DATE TYPES
A class design to manipulate (arithmetic Sub Main()
operation) date and time data structure  Dim myDate As Date = #12/16/2012 12:00:52
AM#
It can contains
 Date End Sub
 Time
 Date and Time

DateTime represent an instant in time


(belong to Microsoft.VisualBasic
namespace)
DateAndTime contain procedures and
properties (belong to System namespace)
DATE TYPES (CONT)
Date Hour Month TimeOfDay
Day Kind Now Today
DayOfWeek Millisecond Second UtcNow
DayOfYear Minute Ticks Year

DateTime Properties
DATE TYPES (CONT)
Public Function Add (value As TimeSpan) As DateTime Public Function AddYears (value As Integer ) As DateTime

Public Function AddDays ( value As Double) As DateTime Public Shared Function Compare (t1 As DateTime,t2 As
DateTime) As Integer
Public Function AddHours (value As Double) As DateTime Public Function CompareTo (value As DateTime) As Integer

Public Function AddMinutes (value As Double) As DateTime Public Function Equals (value As DateTime) As Boolean

Public Function AddMonths (months As Integer) As DateTime Public Shared Function Equals (t1 As DateTime, t2 As
DateTime) As Boolean
Public Function AddSeconds (value As Double) As DateTime Public Overrides Function ToString As String

DateTime Methods
DATE TYPES (CONT)
General Date, or G M, m
Long Date,Medium Date, or D R, r
Short Date, or d s
Long Time,Medium Time, orT u
Short Time or t U
f Y, y
F
g

Date/Time properties
DATE TYPES (CONT)
Date Timer
Now TimeString
TimeOfDay Today

DateAndTime Properties
DATE TYPES (CONT) DateAndTime Methods

Public Shared Function DateAdd (Interval As DateInterval, Public Shared Function Month (DateValue As DateTime) As
Number As Double, DateValue As DateTime) As DateTime Integer
Public Shared Function DateAdd (Interval As String,Number As Public Shared Function MonthName (Month As Integer,
Double,DateValue As Object ) As DateTime Abbreviate As Boolean) As String
Public Shared Function DateDiff (Interval As DateInterval, Public Shared Function Second (TimeValue As DateTime) As
Date1 As DateTime, Date2 As DateTime, DayOfWeek As Integer
FirstDayOfWeek, WeekOfYear As FirstWeekOfYear ) As Long
Public Shared Function DatePart (Interval As DateInterval, Public Overridable Function ToString As String
DateValue As DateTime, FirstDayOfWeekValue As
FirstDayOfWeek, FirstWeekOfYearValue As FirstWeekOfYear )
As Integer
Public Shared Function Day (DateValue As DateTime) As Public Shared Function Weekday (DateValue As DateTime,
Integer DayOfWeek As FirstDayOfWeek) As Integer
Public Shared Function Hour (TimeValue As DateTime) As Public Shared Function WeekdayName (Weekday As Integer,
Integer Abbreviate As Boolean, FirstDayOfWeekValue As
FirstDayOfWeek) As String
Public Shared Function Minute (TimeValue As DateTime) As Public Shared Function Year (DateValue As DateTime) As
Integer Integer
VAL, FORMAT, UCASE
Val Format UCase
Recognize numeric value in a Display numeric values in many Returns a String or character in
variable in order without different forms specified into Upper Case
encountering character and
output it as a String
1,2,3,4,5,6,7,8,9,0 and . Style:- Only lowercase will be
• General Number converted. Others stay the same
• Fixed
• Standard
• Currency
• Percent
Dim MyValue Format(n,”style argument”) ' String to convert.
MyValue = Val("2457") ' Returns 2457. MyValue Dim LowerCase As String = "Hello World
= Val(" 2 45 7") ' Returns 2457. MyValue = Format(n,”user style”) 1234“
Val("24 and 57") ' Returns 24.
' Returns "HELLO WORLD 1234".
Dim UpperCase As String =
UCase(LowerCase)
OPTION EXPLICIT
Explanation Example
Option explicit requires the programmer Dim thisVar As Integer
declares all variable needed to be used in a
source code. thisVar = 10
Any unauthorized or new variable tried to be ' The following assignment produces a
used will render error during compile time
COMPILER ERROR because ' the
It is good practice to use to control code validity. variable is not declared and Option
It must be used before any other code statements Explicit is On.
Option Strict expand this by ensuring declared thisInt = 10 ' causes ERROR
data type cannot be changed
CONSTANTS
Variable with a fixed value Const pie As Double = 3.147
The value can’t be change after being
defined
They are also called literals
Can be in any data types
Enumeration (Enum) constants is a set
of named integer constant
OPERATORS
An Operator is a symbol that perform There are 6 types of operators:-
specific mathematical and logical  Arithmetic
manipulations  Comparison
 Logical / Bitwise
Foundation to form business logic and
 Bit Shift
calculation
 Assignment
 Miscellaneous
ARITHMETIC OPERATOR (A =
2, B = 7)
Operator Description Example

^ Raises one operand to the power of B^A will give 49


another
+ Adds two operands A + B will give 9

- Subtracts second operand from the first A - B will give -5

* Multiplies both operands A * B will give 14

/ Divides one operand by another and B / A will give 3.5


returns a floating point result
\ Divides one operand by another and B \ A will give 3
returns an integer result
MOD Modulus Operator and remainder of after B MOD A will give 1
an integer division
COMPARISON OPERATOR (A =
10, B = 20)
Operator Description Example

= Checks if the values of two operands are equal or (A = B) is not true.


not; if yes, then condition becomes true.

<> Checks if the values of two operands are equal or (A <> B) is true.
not; if values are not equal, then condition
becomes true.

> Checks if the value of left operand is greater than (A > B) is not true.
the value of right operand; if yes, then condition
becomes true.

< Checks if the value of left operand is less than the (A < B) is true.
value of right operand; if yes, then condition
becomes true.

>= Checks if the value of left operand is greater than (A >= B) is not true.
or equal to the value of right operand; if yes, then
condition becomes true.

<= Checks if the value of left operand is less than or (A <= B) is true.
equal to the value of right operand; if yes, then
condition becomes true.
COMPARISON OPERATOR
(CONT)
There are several more comparison operator such as :-
 Is
 It compares two object reference variables and determines if two object references refer to the same object without performing
value comparisons. If object1 and object2 both refer to the exact same object instance, result is True; otherwise, result is False
 IsNot
 It also compares two object reference variables and determines if two object references refer to different objects. If object1 and
object2 both refer to the exact same object instance, result is False; otherwise, result is True.
 Like
 It compares a string against a pattern
LOGICAL / BITWISE
OPERATOR
(A = TRUE, B = FALSE)
Operator Description Example

And It is the logical as well as bitwise AND operator. If both the operands are true, then condition (A And B) is False.
becomes true. This operator does not perform short-circuiting, i.e., it evaluates both the
expressions.

Or It is the logical as well as bitwise OR operator. If any of the two operands is true, then condition (A Or B) is True.
becomes true. This operator does not perform short-circuiting, i.e., it evaluates both the
expressions.

Not It is the logical as well as bitwise NOT operator. Use to reverses the logical state of its operand. Not(A And B) is True.
If a condition is true, then Logical NOT operator will make false.

Xor It is the logical as well as bitwise Logical Exclusive OR operator. It returns True if both A Xor B is True.
expressions are True or both expressions are False; otherwise it returns False. This operator does
not perform short-circuiting, it always evaluates both expressions and there is no short-circuiting
counterpart of this operator.

AndAlso It is the logical AND operator. It works only on Boolean data. It performs short-circuiting. (A AndAlso B) is False.

OrElse It is the logical OR operator. It works only on Boolean data. It performs short-circuiting. (A OrElse B) is True.

IsFalse It determines whether an expression is False.

IsTrue It determines whether an expression is True.


BIT SHIFT OPERATOR (A = 60,
B=13)
Operator Description Example

And Bitwise AND Operator copies a bit to the result if it exists in (A AND B) will give 12, which is 0000
both operands. 1100
Or Binary OR Operator copies a bit if it exists in either operand. (A Or B) will give 61, which is 0011 1101

Xor Binary XOR Operator copies the bit if it is set in one operand (A Xor B) will give 49, which is 0011
but not both. 0001
Not Binary Ones Complement Operator is unary and has the effect (Not A ) will give -61, which is 1100 0011
of 'flipping' bits. in 2's complement form due to a signed
binary number.
<< Binary Left Shift Operator. The left operands value is moved A << 2 will give 240, which is 1111 0000
left by the number of bits specified by the right operand.
>> Binary Right Shift Operator. The left operands value is moved A >> 2 will give 15, which is 0000 1111
right by the number of bits specified by the right operand.
ASSIGNMENT OPERATOR
Operator Description Example

= Simple assignment operator, Assigns values from right side operands to left side operand C = A + B will assign value of A + B into C

+= Add AND assignment operator, It adds right operand to the left operand and assigns the result to left C += A is equivalent to C = C + A
operand

-= Subtract AND assignment operator, It subtracts right operand from the left operand and assigns the result C -= A is equivalent to C = C - A
to left operand

*= Multiply AND assignment operator, It multiplies right operand with the left operand and assigns the result C *= A is equivalent to C = C * A
to left operand

/= Divide AND assignment operator, It divides left operand with the right operand and assigns the result to C /= A is equivalent to C = C / A
left operand (floating point division)

\= Divide AND assignment operator, It divides left operand with the right operand and assigns the result to C \= A is equivalent to C = C \A
left operand (Integer division)

^= Exponentiation and assignment operator. It raises the left operand to the power of the right operand and C^=A is equivalent to C = C ^ A
assigns the result to left operand.

<<= Left shift AND assignment operator C <<= 2 is same as C = C << 2

>>= Right shift AND assignment operator C >>= 2 is same as C = C >> 2

&= Concatenates a String expression to a String variable or property and assigns the result to the variable or Str1 &= Str2 is same as
property. Str1 = Str1 & Str2
MISCELLANEOUS OPERATORS
Operator Description Example

AddressOf Returns the address of a procedure. AddHandler Button1.Click, AddressOf


Button1_Click
Await It is applied to an operand in an asynchronous method or lambda Dim result As res = Await
expression to suspend execution of the method until the awaited AsyncMethodThatReturnsResult() Await
task completes. AsyncMethod()
GetType It returns a Type object for the specified type. The Type object MsgBox(GetType(Integer).ToString())
provides information about the type such as its properties,
methods, and events.
Function Expression It declares the parameters and code that define a function lambda Dim add5 = Function(num As Integer)
expression. num + 5 'prints 10
Console.WriteLine(add5(5))
If It uses short-circuit evaluation to conditionally return one of two Dim num = 5 Console.WriteLine(If(num
values. The If operator can be called with three arguments or >= 0, "Positive", "Negative"))
with two arguments.
OPERATORS PRECEDENCE Operator Precedence

Await Highest

Exponentiation (^)

Unary identity and negation (+, -)

Multiplication and floating-point division (*, /)

Integer division (\)

Modulus arithmetic (Mod)

Addition and subtraction (+, -)

Arithmetic bit shift (<<, >>)

All comparison operators (=, <>, <, <=, >, >=, Is, IsNot, Like, TypeOf...Is)

Negation (Not)

Conjunction (And, AndAlso)

Inclusive disjunction (Or, OrElse)

Exclusive disjunction (Xor) Lowest


DECISION MAKING
STATEMENTS
Decision making statements provide
multiple outcomes to be selected
depending on a or a set of conditions
Its divided into test statements
(evaluation statements) with result true
or false and each with its own code
execution
Basis of program logic
DECISION MAKING
STATEMENTS (CONT)
Statement
If ... Then statement
If...Then...Else statement
nested If statements
Select Case statement
nested Select Case statements
LOOPS
Repeated execution of a block of code
can be implemented with loops
Rather than writing the same code
repeatedly, this will make the code
compact thus more efficient
Could be form to create a more complex
program structures
LOOPS (CONT)
Loops
Do Loop
For...Next
For Each...Next
While... End While
With... End With
Nested loops
EXIT & CONTINUE
Control Statement Description
Exit statement Terminates the loop or select case statement and
transfers execution to the statement immediately
following the loop or select case.
Continue statement Causes the loop to skip the remainder of its body
and immediately retest its condition prior to
reiterating.
SUB PROCEDURE AND
FUNCTION
Sub Function
Procedures that doesn’t return any value Procedures that return a value
In console application, the main is a For example :-
type of sub  [Modifiers] Function FunctionName
(ParameterList) As ReturnType
For example :-  Statements
 [Modifiers] Sub SubName (ParameterList)  Return value
 Statements  End Function
 End Sub
BYVAL VS BYREF
ByVal ByRef
A variable copy of actual reference Copied the reference of a variable
value is created
Any changes will affect the original
Changes on the copy did not affect the value
actual value
Syntax example:-
Syntax example:-  Sub mySwap(ByRef x As Integer)
 Sub mySwap(ByVal x As Integer)  MessageBox.Show(“The value is : ” +x)
 MessageBox.Show(“The value is : ” +x)  End Sub
 End Sub
ARRAY
An array stores a fixed-size sequential collection of elements of the same type
It also can be considered as a variable that has multiple values of the same type
Multiples values was identified by their placement called as index.
Index start with 0 (the first value) to n (the last element)
Once the range of the array is defined, it can’t increase it unless redefined with
preserve keyword
Preserve save the copy of the existing element before increase the range of the array
Module arrayApl

ARRAY (CONT) Sub Main()


Dim n(10) As Integer ' n is an array of 11 integers '
Dim i, j As Integer
' initialize elements of array n '
Example of Array
For i = 0 To 10
n(i) = i + 100 ' set element at location i to i + 100
Next i
' output each array element's value '

For j = 0 To 10
Console.WriteLine("Element({0}) = {1}", j, n(j))
Next j
Console.ReadKey()
End Sub
End Module
Module arrayApl

ARRAY (CONT) Sub Main()


Dim marks() As Integer
ReDim marks(2)
marks(0) = 85
marks(1) = 75
marks(2) = 90
Dynamic Arrays
• Array can re dimension using preserve keyword ReDim Preserve marks(10)
marks(3) = 80
marks(4) = 76
marks(5) = 92
marks(6) = 99
marks(7) = 79
marks(8) = 75

For i = 0 To 10
Console.WriteLine(i & vbTab & marks(i))
Next i
Console.ReadKey()
End Sub
End Module
Module arrayApl
ARRAY (CONT) Sub Main()
' an array with 5 rows and 2 columns
Dim a(,) As Integer = {{0, 0}, {1, 2}, {2, 4}, {3, 6}, {4, 8}}
Multidimensional Array Dim i, j As Integer
' output each array element's value '

For i = 0 To 4
For j = 0 To 1
Console.WriteLine("a[{0},{1}] = {2}", i, j, a(i, j))
Next j
Next i
Console.ReadKey()
End Sub
End Module
Sr.No Property Name & Description
ARRAY (CONT) 1 IsFixedSize
Gets a value indicating whether the Array has a
fixed size.

Array Properties
2 IsReadOnly
Gets a value indicating whether the Array is read-
only.
3 Length
Gets a 32-bit integer that represents the total
number of elements in all the dimensions of the
Array.
4 LongLength
Gets a 64-bit integer that represents the total
number of elements in all the dimensions of the
Array.
5 Rank
Gets the rank (number of dimensions) of the Array.
Sr.No Method Name & Description

ARRAY (CONT) 1 Public Shared Sub Clear (array As Array, index As Integer, length As
Integer)

2 Public Shared Sub Copy (sourceArray As Array, destinationArray As


Array, length As Integer)

3 Public Sub CopyTo (array As Array, index As Integer)


Array Methods
4 Public Function GetLength (dimension As Integer) As Integer

5 Public Function GetLongLength (dimension As Integer) As Long

6 Public Function GetLowerBound (dimension As Integer) As Integer

7 Public Function GetType As Type

8 Public Function GetUpperBound (dimension As Integer) As Integer

9 Public Function GetValue (index As Integer) As Object

10 Public Shared Function IndexOf (array As Array,value As Object) As


Integer

11 Public Shared Sub Reverse (array As Array)

12 Public Sub SetValue (value As Object, index As Integer)

13 Public Shared Sub Sort (array As Array)

14 Public Overridable Function ToString As String


CLASS, OBJECT AND
METHODS
Class is a blueprint of a datatype without containing any value
Since it lack any value it can’t be considered as data
It is object definition which describe the structure and operations (methods) it can execute
Object is an instance of a class
Object is a data since it hold values and can be manipulated
Class definition
 [attribute list] [access modifier] [Shadows] [MustInherit | NotInheritable] Class ClassName …
 [Of typelist] [Inherits ClassName] [Implements InterfaceNames]
 Statements
 End Class

More explanation click here.


Object definition:- Dim abc As ClassName = new ClassName()
CLASS, OBJECT AND
METHODS (CONT)
Variables and Subs/Functions is a member of a class
Methods = Subs/Functions in a class
Syntax example :-
 [Access Modifier] Sub/Function Name (parameter list) [If Function : As returnType]
 Statements
 If Function : return value
 End Sub/Function
CLASS, OBJECT Class Calculate

AND METHODS Public length As Double ' Length of a box


Private breadth As Double ' Breadth of a box

(CONT) Private height As Double ' Height of a box


Public Sub setLength(ByVal len As Double)
length = len
Class example End Sub

Public Sub setBreadth(ByVal bre As Double)


breadth = bre
End Sub

Public Sub setHeight(ByVal hei As Double)


height = hei
End Sub

Public Function getVolume() As Double


Return length * breadth * height
End Function
End Class
Class Line
Private length As Double ' Length of a line

CLASS, OBJECT
Public Sub New() 'constructor
Console.WriteLine("Object is being created")

AND METHODS End Sub

(CONT) Public Sub New(ByVal len As Double) ‘parameterized


Console.WriteLine("Object is being created with: “ & len)
End Sub
Constructors and Destructors
• Constructors Public Sub New(ByVal len As Double, ByVal wid As Double) ‘overloaded
• Method called when object first created Console.WriteLine("Object is being created “ & len & “with” &wid )
• Sub Procedure with named ‘New’ with no return value
End Sub
• Destructors
• Methods called when object goes out of scope Public Sub setLength(ByVal len As Double)
• Sub Procedure with named ‘Finalize’ with no return length = len
value
End Sub

Public Function getLength() As Double


Return length
End Function
Protected Overrides Sub Finalize() ' destructor
Console.WriteLine("Object is being deleted")
End Sub
CLASS, OBJECT AND
METHODS (CONT)
Object Oriented Programming is the focus of VB.NET where VB6 lack.
It support 4 concepts of OOP which are:-
 Abstraction
 Encapsulation
 Inheritance
 Polymorphism
Class Shape
CLASS, OBJECT Protected width As Integer
AND METHODS Protected height As Integer

(CONT) Public Sub setWidth(ByVal w As Integer)


width = w
Abstraction End Sub
• By providing features / usefulness but hiding Public Sub setHeight(ByVal h As Integer)
the actual implementation or complexities is height = h
called abstraction
End Sub
• A class is actually hiding / encasing the End Class
implementation
• By creating a class and defined attributes and
methods within is an abstraction
• MessageBox class is a good example where a
programmer know how to use it using methods
but inner working are actually unknown
CLASS, OBJECT Class Shape
AND METHODS Private width As Integer

(CONT) Private height As Integer


Public Sub setWidth(ByVal w As Integer)
Encapsulation width = w
• Data hiding to prevent direct interaction or End Sub
manipulation Public Sub setHeight(ByVal h As Integer)
• Data in a class is called attributes height = h
• Attributes access modifier is Private End Sub
• Attributes of an object can only be manipulated End Class
by methods within the class.
• Method access modifier is Public
Class Shape

CLASS, OBJECT
Protected width As Integer
Protected height As Integer

AND METHODS Public Sub setWidth(ByVal w As Integer)


width = w

(CONT) End Sub


Public Sub setHeight(ByVal h As Integer)
height = h
Inheritance End Sub
• A class can be used as a base structure of a new End Class
class Class Rectangle : Inherits Shape
Public Function getArea() As Integer
• This allow systematic data structure if the data
Return (width * height)
is similar or contain resemblance of pattern
End Function
• It’s a deriving a class from a base class End Class
• Relation Class RectangleTester
• Superclass create Subclass Shared Sub Main()
• Parent create Child Dim rect As Rectangle = New Rectangle()
rect.setWidth(5)
rect.setHeight(7)
' Print the area of the object.
Console.WriteLine("Total area: {0}", rect.getArea())
Console.ReadKey()
End Sub
End Class
CLASS, OBJECT AND
METHODS (CONT)
Polymorhphism
• Multiple class having the same interface but different implementation
• It can be used either through inheritance and without.
• For example Proton Satria class and Honda Civic class, both are derived from Car class and both
have method drive().
• This could be achieved with interfaces
• An interface defines a set of properties and methods that a class should implement
• This is called early binding and it greatly improve performance
CLASS, OBJECT AND
METHODS (CONT)
Public Interface IAmusementParkRide Public Class MerryGoRound
Sub Ride()
End Interface Implements IAmusementParkRide
Public Sub
Public Class RollerCoaster IAmusementParkRide_Ride()
Implements IAmusementParkRide
Public Sub IAmusementParkRide_Ride() Console.WriteLine("OK will go on it")
Console.WriteLine("Here we go") Console.Writeline("Nap Time")
Console.WriteLine("Click, Click ,Click")
Console.WriteLine("Oh, *&@&#%") Console.WriteLine("Yea its over")
Console.WriteLine("That was great") End Sub
End Sub
End Class
CLASS, OBJECT AND
METHODS (CONT)
Private Sub DayAtTheAmusementPark()
Dim oRollerCoaster as New RollerCoaster
Dim oMerryGoRound as New MerryGoRound
Call GoOnRide(oRollerCoaster)
Call GoOnRide(oMerryGoRound)
End Sub
Private Sub GoOnRide(oRide as IAmusementParkRide)
oRide.Ride()
End Sub
REFERENCE

You might also like