Create a new object using the text name of the class

后端 未结 5 1605
刺人心
刺人心 2020-12-06 07:00

Is there a way to set an object to the new instance of a class by using the text name of the class?

I will have a library of classes, and depending on some other var

5条回答
  •  死守一世寂寞
    2020-12-06 07:15

    You might be able to do it with a collection class or object array. All the objects are in one array.

    In your class have a .Name property and when you create an instance of it do this:

    Dim CTest() as New CTest
    For n = 1 to 10
        Redim Preserve CTest(n)
        CTest(n).Name = "CTest" & CStr(n)
    Next l
    

    Quick and dirty. The above example would return 10 CTest objects in a single object array. You could also ditch the .Name and just use CTest(n).

提交回复
热议问题