?
Solved

vb6 class module

Posted on 2004-10-08
3
Medium Priority
?
1,275 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 70

Accepted Solution

by:
Éric Moreau earned 700 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 100 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 86

Assisted Solution

by:Mike Tomlinson
Mike Tomlinson earned 200 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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.
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 Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Suggested Courses

649 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