Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language:
Expertise: Beginner
Aug 7, 1997

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 of different 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 parameter
Public 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



Hassan Davis
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date