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
Solved

vb6 class module

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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…

829 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