When using a pointer to point to a Form or a Class or a Module ... which is better to use .... a pointer declared as a Variant or as an Object ??? (And why?) Thanks!
(I originally posted this in the wrong area - my apologies)
Dim var as Variant
var = 12982
Set var = Nothing
Set var = New Adodb.Recordset
Set var = Nothing
Set var = CreateObject("MyDLLName.ClassName")
'etc.
but if you know what you need the pointer/variable for, then the better way is to use the actual object.
i.e. Don't use object use the actual DLL.
Code:
'Bad Way
Dim obj As Object
Set obj = CreateObject("MyDLLName.ClassName")
'Good Way
Dim obj As MyDLLName.ClassName
Set obj = CreateObject("MyDLLName.ClassName")
Casper
There is room for all of gods creatures, "Right Beside the Mashed Potatoes".
I am still new to this and have never written or referenced DLLs ... what I want to do is call code from Forms, Modules, and Classes generically ie ... have references to them passed as a parameter to a routine that will then use a that reference to call a routine of a pre-defined name from it. Does that make sense? I know that Variants and Objects are pretty generic ... but which would be better to set to say, a Class from within a project (not a DLL)? Thanks
Private Sub MyFunction(ByVal i_sClassName)
Select Case i_sClassName
Case "Class1"
DIM obj as MyClasses.Class1
Case "Class2"
DIM obj as MyClasses.Class2
Case "Class2"
DIM obj as MyClasses.Class2
End Select
Set obj = CreateObject(i_sClassName)
obj.DoSomething
Set obj = Nothing
End Sub
but you could do this...
Code:
Private Sub MyFunction(ByVal i_sClassName)
Dim obj as Object
CallByName i_sClassName, "DoSomething", VbMethod
End Sub
Casper
There is room for all of gods creatures, "Right Beside the Mashed Potatoes".
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.