Solved

vb6 class module

Posted on 2004-10-08
3
1,244 Views
Last Modified: 2013-12-26
Hello

  I am trying to create a class module in vb6,

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

thank you
0
Comment
Question by:omarmf
3 Comments
 
LVL 69

Accepted Solution

by:
Éric Moreau earned 175 total points
ID: 12259167
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"
    X.DoSomething

End Sub
0
 
LVL 26

Assisted Solution

by:EDDYKT
EDDYKT earned 25 total points
ID: 12259281
May be you should use addin

ie

Add-ins->Addin managers->Vb6 class builder utility (check on loaded/unloaded)->click ok
0
 
LVL 85

Assisted Solution

by:Mike Tomlinson
Mike Tomlinson earned 50 total points
ID: 12260059
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
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now