• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 174
  • Last Modified:

Dynamically call a class startup

Hi all.  I am pulling in some class names from a INI file.  I need to call the class file startup with that name.  For example, I have account numbers such as XYZ123, ABC555

In my VB code I need to append "cls" to that string such as clsXYZ123 and then call clsXYZ123.Startup

Any help?

I tried dimming an object but no dice
  • 2
2 Solutions
Mike TomlinsonMiddle School Assistant TeacherCommented:
What VB are you working in here?...

VBScript, VBA, VB6, VB.net 2003 (or below), VB.Net 2005

And what is "Startup"?  Is that a sub/method in the class or are you trying to make the constructor fire?

Give us a bigger picture of what you are doing.
an easy solution is to use an If or switch by your init name XYZ123, and crete a class in if or switch case.
sbornstein2Author Commented:
working in VB6.0.  Here is the sample code:

Public Sub cmdLogin_Click()
Dim i As Integer
Dim editSplit
Dim strEdit As String
Dim objClass As Object

    editSplit = Split(IUREdits, ",")
    'Run each edit for IUR

    For i = LBound(editSplit) To UBound(editSplit)
        strEdit = Trim(editSplit(i))
        'First import all text file data for new week run
        clsImportData.ImportReports (strEdit)
        'Next run the corresponding class Startup
        objClass = "cls" & strEdit
        Set objClass = New objClass
        'Finally CleanUp Access DB
End Sub

the strEdit will have what I want to call with "cls"" in front
Mike TomlinsonMiddle School Assistant TeacherCommented:
I think you would need to use COM to do that type of setup in VB6.  So your classes would need to be ActiveX DLLs...
Then you could use CreateObject():

VB.Net can instantiate objects like that internally using Reflection.

AlexNek has already suggested a big switch...
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now