Solved

vb6 class module

Posted on 2004-10-08
3
1,254 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 70

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

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

772 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