Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

VB6-Class Builder ActiveX -Hierarchy

Posted on 2000-04-11
6
Medium Priority
?
159 Views
Last Modified: 2010-05-02
Hi, I have a Single Class : TheLibrary.MyLibrary.

In MyLibrary I have several properties and functions.

TheLibrary
  - MyLibrary
    o Many properties (say 20)
    > Many methods (say 50)

- Denotes Class
o Denotes Property
> Denotes Method



Now I want create a class hierarchy, as I only have a single
class with a flat structure of properties and functions.

Let say I have a property called HelloConstant.

ie:  TheLibrary.MyLibrary.HelloConstant : String;

I now want to add a sub class called Messages
  TheLibrary.MyLibrary.Messages
  which I have done using the Classbuilder

so my tree view looks like:

TheLibrary
  - MyLibrary
    o All my other properties...
    o HelloConstant
    > All my other methods
    - Messages
      > DisplayTheHelloConstant

- Denotes Class
o Denotes Property
> Denotes Method


My sub for DisplayTheHelloConstant is:

Public Sub DisplayTheHelloConstant()
  MsgBox (HelloConstant)
End Sub

which does not work because the Messages.cls doesn't seem to be able
to access the MyLibrary class property HelloConstant.

I want the client to run code that looks like this:

  MyLibraryObj.HelloConstant = "Hello world"
  MyLibraryObj.Messages.DisplayTheHelloConstant

But I cant figure out what I should do for the DisplayTheHelloConstant function..

Thanks
Berto.
0
Comment
Question by:RDurando
[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
  • 4
  • 2
6 Comments
 
LVL 10

Expert Comment

by:caraf_g
ID: 2703470
Assuming that MyLibrary and Messages are in the same project

In Messages you can declare a Friend property


In general declarations:
Private mobjMyLibrary As MyLibrary

Friend Property Set FriendLibrary(objNew as MyLibrary)

Set mobjMyLibrary = objNew

End Property

When your MyLibrary instantiates the Messages Object, follow that immediately with
Set Messages.FriendLibrary = Me

Once you've done that, your Messages class can access the HelloConstant variable of its parent MyLibrary object by FriendLibrary.HelloConstant

And because the property FriendLibrary is defined as a Friend property, code outside the project cannot access it.

Hope this helps!

Pino
0
 
LVL 10

Accepted Solution

by:
caraf_g earned 160 total points
ID: 2703474
Public Sub DisplayTheHelloConstant()
  MsgBox (mobjMyLibrary.HelloConstant)
End Sub

0
 

Author Comment

by:RDurando
ID: 2703542
Pino : you're loosing me...

I'm sure you know what you are doing, but I can't see what it is at the moment.


Let me try again :

This is my DLL:
==============================
TheLibrary
  - MyLibrary
    o All my other properties...
    o HelloConstant
    > All my other methods
    - Messages
      > DisplayTheHelloConstant

- Denotes Class
o Denotes Property
> Denotes Method


This is my Client Application:
==============================
Dim MyLibraryObj As MyLibrary

Private Sub Form_Load()
  Set MyLibraryObj = New MyLibrary
End Sub

Private Sub Command5_Click()
  MyLibraryObj.HelloConstant = "Hello world"
  MyLibraryObj.Messages.DisplayTheHelloConstant <---This line Does not Run.
End Sub


This line does not run because I have not setup my DLL Correctly.

In my DLL project I have 2 class modules:
MyLibrary
Messages



MyLibrary looks like this:
==============================
'local variable(s) to hold property value(s)
Private mvarHelloConstant As String 'local copy
Private mvarMessages As Messages

Public Property Get Messages() As Messages
    Set Messages = mvarMessages
End Property

Public Property Set Messages(vData As Messages)
    Set mvarMessages = vData
End Property

Private Sub Class_Terminate()
    Set mvarMessages = Nothing
End Sub

Public Property Let HelloConstant(ByVal vData As String)
    mvarHelloConstant = vData
End Property

Public Property Get HelloConstant() As String
    HelloConstant = mvarHelloConstant
End Property

Private Sub Class_Initialize()
  Set mvarMessages = New Messages
End Sub


Messages looks like this:
==============================
Public Sub DisplayTheHelloConstant()
'  MsgBox (???.HelloConstant)
End Sub

Private Sub Class_Initialize()
???
End Sub

Help...
0
Industry Leaders: 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!

 
LVL 10

Expert Comment

by:caraf_g
ID: 2703586
MyLibrary looks like this:
==============================
'local variable(s) to hold property value(s)
Private mvarHelloConstant As String 'local copy
Private mvarMessages As Messages

Public Property Get Messages() As Messages
    Set Messages = mvarMessages
End Property

Public Property Set Messages(vData As Messages)
    Set mvarMessages = vData
End Property

Private Sub Class_Terminate()
    Set mvarMessages = Nothing
End Sub

Public Property Let HelloConstant(ByVal vData As String)
    mvarHelloConstant = vData
End Property

Public Property Get HelloConstant() As String
    HelloConstant = mvarHelloConstant
End Property

Private Sub Class_Initialize()
    Set mvarMessages = New Messages
    Set mvarMessages.FriendLibrary = Me
End Sub


Messages looks like this:
==============================
Private mobjMyLibrary As MyLibrary
Friend Property Set FriendLibrary(objNew As MyLibrary)
    Set mobjMyLibrary = objNew
End Property
Public Sub DisplayTheHelloConstant()
    MsgBox (mobjMyLibrary.HelloConstant)
End Sub

0
 
LVL 10

Expert Comment

by:caraf_g
ID: 2703601
Or, even better:

MyLibrary looks like this:
==============================
'local variable(s) to hold property value(s)
Private mvarHelloConstant As String 'local copy
Private WithEvents mvarMessages As Messages

Public Property Get Messages() As Messages
    Set Messages = mvarMessages
End Property

Public Property Set Messages(vData As Messages)
    Set mvarMessages = vData
End Property

Private Sub Class_Terminate()
    Set mvarMessages = Nothing
End Sub

Public Property Let HelloConstant(ByVal vData As String)
    mvarHelloConstant = vData
End Property

Public Property Get HelloConstant() As String
    HelloConstant = mvarHelloConstant
End Property

Private Sub Class_Initialize()
    Set mvarMessages = New Messages
End Sub

Private Sub mvarMessages_GetHelloConstant(strConstant As String)
    strConstant = mvarHelloConstant
End Sub



Messages looks like this:
==============================
Public Event GetHelloConstant(strConstant As String)
Public Sub DisplayTheHelloConstant()
    Dim strConstant As String
    RaiseEvent GetHelloConstant(strConstant)
    MsgBox strConstant
End Sub
0
 

Author Comment

by:RDurando
ID: 2703640
Thanks very much for your help
Berto;-)
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

650 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