devxlogo

Determine the Class of YourObject with the TypeOf Statement

Determine the Class of YourObject with the TypeOf Statement

In VB4 the TypeOf statement works with any valid object type,not just forms and controls. This allows you to pass objects ofdifferent classes to the same procedure for a class-specific implementation.Here is an example:

 'This procedure prints information 'specific to the object referenced 'in the YourObject parameterPublic Sub PrintObjectInfo(YourObject _        As Object)                If TypeOf YourObject Is CDesk Then        ' tell what type of object this is                Print "Object Type: Desk"                ' print the number of legs that                 'this object has                Print "Number of legs: " & Your_                    Object.NumberOfLegs        ElseIf TypeOf YourObject Is CHouse _                Then        ' tell what type of object this is                Print "Object Type: House"                Print "Number of doors: " & Your_                        Object.NumberOfDoors        End If        ' both classes have the following         ' properties        Print "Height: " & YourObject.                Height & " ft."        Print "Width: " & YourObject.Width _                & " ft."        Print "Built by: " & YourObject._                BuilderName         Print "Purchase date: " & Your_                Object.PurchaseDate         Print "Purchase price: $" & Your_                Object.PurchasePrice                .                .  .  .End Sub
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist