View Full Version : callin functions between class modules

2004-07-09, 07:21 PM
i have a vba and some class modules in the same dll
lets suppose this public fuction is in a class module called class1

Public Function Dist2Puntos(PuntoA As Variant, PuntoB As Variant) As Variant
Dim Longitud As Variant
Longitud = Sqr(((PuntoA(0) - PuntoB(0)) ^ 2) + ((PuntoA(1) - PuntoB(1)) ^ 2) + ((PuntoA(2) - PuntoB(2)) ^ 2))
Dist2Puntos = Longitud
End Function

if i am operating autocad from a sub in a class module called class2,
Public Sub SumaAdll(xssArea As AcadSelectionSet)
End sub

how can i use the funcion, i dont know the way to call the function 'Dist2Puntos' of the class module 1 while operating in the sub of class module 2

thanks in advance

Ed Jobe
2004-07-09, 07:54 PM
I'm a little unclear as to exactly how you have your code organized, since vba isn't contained in a dll, but a dvb. However, the principle is the same. If your "classes" (toolbox functions like you've shown should be in regular modules, not class modules) are all in the same dvb and are public, you only need to call them by the procedure name. If you have your public functions/subs in another dvb, (I keep mine in Toolbox.dvb), then you need to reference Toolbox.dvb and call the function using a fully qualified name, i.e. "ProjectName.ModuleName.ProcedureName" or "Toolbox.Module1.Dist2Puntos".

2004-07-09, 08:01 PM
the functions, sub are in a dll
i first run the vba in autocad, and after that i call class modules of the dll

Dim VB6DLL2 As Object
Dim VB6DLL3 As Object

Set VB6DLL2 = ThisDrawing.Application.GetInterfaceObject("External.ExternalClass2")
Set VB6DLL3 = ThisDrawing.Application.GetInterfaceObject("External.ExternalClass3")

so, i am trying to organizate the dll, some general functions in External.ExternalClass2
and some subs in External.ExternalClass3

the problem is to call a function that belong to a class module 2 while i am operating in class module 3, for example

i was working with modules and public sub/functions in the vba, but i need to translate the code to a dll and now i have some problems

2004-07-10, 03:40 PM
You are late-binding your class in the .dll. When you early-bind your class, you can easily see the public methods and properties (procedures and variables) of the referenced class.

From the VBA procedure with a reference to your .dll (assumes dll class is named 'class1' :screwy: ):

Sub Test
Dim myObj as Class1
Set myObj = New Class1

Dim pt1(0 to 2) As Double
Dim pt2(0 to 2) As Double

Dim resBack
resBack = myObj.Dist2Puntos(pt1, pt2)

Set myObj = Nothing
End Sub

2004-07-10, 11:48 PM
finally i am usign this to call a function in a class from vba

Sub ...
Dim VB6DLL As Object
Set VB6DLL = ThisDrawing.Application.GetInterfaceObject("External.ExternalC")
VB6DLL.SumaAreaEC (ssArea)
Set VB6DLL = Nothing
End Sub

and this to call a function in a class from other class in the same dll

Sub ...
Dim VB6DLL As Object
Set VB6DLL = GetInterfaceObject("External.ExternalC")
VB6DLL.SumaAreaEC (ssArea)
Set VB6DLL = Nothing
End Sub

dont know the difference but it works