isabelle
February 15th, 2000, 03:24 PM
I have a public object "a" (public on a form only). The type of this object depend of a choice from the user. I must keep the same name ("a") for both types.
First, can I do this and second, how??!
Thanks for all help you can give to me,
Isabelle
Kyle Burns
February 15th, 2000, 03:46 PM
1) If you declare a variable as Public, then it is public to the entire project. If you want the object to be accesible to all procedures within the form, Declare it with Private scope in the General Declarations section of your module.
2)I think this is what you want to do:
'In Genral Declarations...
Dim a as Object
'Later in your code...
private Sub ChooseAObjectType(iType as Integer)
'Check to see if the object has already
'been set. If so, set it to nothing
If Not a is nothing then
set a = nothing
End If
Select Case iType
Case 0
set a = CreateObject("SomeLib.SomeClass")
Case 1
set a = CreateObject("SomeOtherLib.SomeOtherClass")
End Select
End Sub
You need to take care when you're using one variable that can possibly be objects of different types that you don't call a method of the object that doesn't exist. Take a look at TypeOf
Kyle