Class name as a Parameter

  • Thread starter Thread starter Max Yaffe
  • Start date Start date
M

Max Yaffe

Dear Newsgroup,

Is it possible to parameterize a class name? For example:

Public Gfrm as Form

Public Sub MakeNewObject(myFormClass as ???)

Set Gfrm = New myFormClass

Gfrm.Visible = True

End Sub


Thanks for your help.
Max
 
Yes...but it would help to know more about what you are trying to
accomplish. Your code doesn't make sense. The purpose of Gfrm in your
example is unclear.

Public Sub DoSomething(x as Form)
'Manipulate an existing object
x.Visible = True

End Sub

In this case, x should have already been instantiated by the calling
routine.

Public Function DoSomethingElse() As Form
'Create a new object and return it for use by calling routine
Set DoSomethingElse = New SomeFormClass
DoSomethingElse.Visible = True

End Function
 
Dear Paul

I'm sorry if my code wasn't clear. Let me restate my routine &
explain it

Public Gfrm as Form

Public Sub MakeNewObject(myFormClass as ???)
Set Gfrm = New myFormClass
Gfrm.Visible = True
End Sub

Gfrm is public so that the newly created form is not deallocated when
MakeNewObject returns. I'll restate it using a function if that is
less confusing

Public Function MakeNewObject() As Form
Set MakeNewObject = New myFormClass
MakeNewObject.Visible = True
End Function

The problem is this -- I have several different forms that are
created in the same way, e.g.

Public Function MakeNewFormA() As Form
Set MakeNewFormA = New Form_FormA
MakeNewFormA.Visible = True
...
End Function

Public Function MakeNewFormB() As Form
Set MakeNewFormB = New Form_FormB
MakeNewFormB.Visible = True
...
End Function

Public Function MakeNewFormC() As Form
Set MakeNewFormC = New Form_FormC
MakeNewFormC.Visible = True
...
End Function

I'd like to have one function that looks something like

Public Function MakeNewForm(FormClass as ???) As Form
Set MakeNewForm = New FormClass
MakeNewForm.Visible = True
...
End Function

But I don't know what datatype FormClass should be (hence the '???').

Can you enlighten me?
Thanks
Max
 
Back
Top