Solved

Referring to other classes in the same DLL

Posted on 1998-08-05
4
141 Views
Last Modified: 2010-05-03
Hello,
I am a VB student with the following problem:

I have a standard project with a standard startup module (StartModule).
I have a DLL(DLLA) with two classes (ClassA and ClassB).

StartModule has instantiated examples of both ClassA and ClassB.  I want ClassA to be able to
call ClassB via the instance of ClassB started by StartModule.

I have got this far:

STARTMODULE:
Declarations:
public ExampleA as new ClassA

Main:
set exampleA.objparent = me

DLLA:ClassA (and ClassB)
Declarations:
public objparent as ?????????? what

I can't say "public objparent as StartModule" because VB wont recognise that.  StartModule is not a class and it is in a separate project.

(I was thinking of referring to ClassB from ClassA as "Startmodule.ClassB")

In essence I am trying to get one class in a DLL to call another class in the same DLL.  But as they are separate instances I am not sure how to do it.

I would be most grateful for a solution with code examples.

Thanks,
TrimTrom
0
Comment
Question by:trimtrom
  • 3
4 Comments
 
LVL 2

Accepted Solution

by:
percosolator earned 100 total points
ID: 1468032
ok.  here is sample code to show you how to pass instances about.

------------------------------------------------------------


Option Explicit


'Start Module
Public ExampleA As New ClassA
Public ExampleB As New ClassB

Public Sub main()


       
    'Set ExampleA's ClassB object to the Start Module's Instance
    Set ExampleA.MyClassB = ExampleB
   
    'set example B's Message property
    ExampleB.Message = "This Message is Available to Both Sub Main," & _
                        "And the Instance of ClassA"

    'display ExampleB's Message
    ExampleB.PrintMessage
   
    'show that ExampleA is using the same instance of ExampleB
    'by displaying ExampleA's instance of ClassB's message
    ExampleA.ShowClassBMessage
   

End Sub


-------------------------------------------------------------


'Class A

Option Explicit

Dim objClassB As ClassB

Public Property Set MyClassB(C As ClassB)
    Set objClassB = C
End Property

Public Sub ShowClassBMessage()

    objClassB.PrintMessage
   
End Sub


----------------------------------------------


'ClassB

Option Explicit

Dim strMessage As String
Public Property Let Message(S As String)

    strMessage = S
   
End Property
Public Sub PrintMessage()

        MsgBox strMessage
       
End Sub


----------------------------------------


0
 

Author Comment

by:trimtrom
ID: 1468033
OK Thanks very much.  A very clear and concise answer.
0
 
LVL 2

Expert Comment

by:percosolator
ID: 1468034
you are welcome.
0
 
LVL 2

Expert Comment

by:percosolator
ID: 1468035
I occasionally have brief moments of lucidity. <g>


Anytime...
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

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…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…
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…

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