• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1278
  • Last Modified:

vb6 class module


  I am trying to create a class module in vb6,

i need any dummy example just to see the way in vb6

thank you
3 Solutions
Éric MoreauSenior .Net ConsultantCommented:
Here is the content of Class1.cls

Option Explicit

Private mstrLastName As String
Private mstrFirstName As String

Public Property Get FirstName() As Variant
    FirstName = mstrFirstName
End Property
Public Property Let FirstName(ByVal vNewValue As Variant)
    mstrFirstName = vNewValue
End Property

Public Property Get LastName() As Variant
    LastName = mstrLastName
End Property
Public Property Let LastName(ByVal vNewValue As Variant)
    mstrLastName = vNewValue
End Property

Public Sub DoSomething()
    MsgBox FirstName & " " & LastName
End Sub

Here is how to use it from a button on a form:

Private Sub Command1_Click()
Dim X As New Class1

    X.FirstName = "Eric"
    X.LastName = "Moreau"

End Sub
May be you should use addin


Add-ins->Addin managers->Vb6 class builder utility (check on loaded/unloaded)->click ok
Mike TomlinsonMiddle School Assistant TeacherCommented:
The Initialize() and Terminate() events for a class are very useful as well.  The Initialize() event fires when in instance of the class is created and can be used to set initial values for your class members or do initialization code.  The Terminate() event fires just before the class instance is destroyed.  You could the code below to emoreaus example to set initial values for the first and last name:

Private Sub Class_Initialize()
    mstrFirstName = "Some"
    mstrLastName = "One"
End Sub

Private Sub Class_Terminate()
    ' place code in here that needs to be executed
    ' before this class instance is destroyed
End Sub
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

7 new features that'll make your work life better

It’s our mission to create a product that solves the huge challenges you face at work every day. In case you missed it, here are 7 delightful things we've added recently to monday to make it even more awesome.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now