Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Dynamically call a class startup

Posted on 2006-11-17
4
Medium Priority
?
171 Views
Last Modified: 2010-04-16
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
0
Comment
Question by:sbornstein2
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 17969253
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.
0
 
LVL 16

Assisted Solution

by:AlexNek
AlexNek earned 400 total points
ID: 17974627
an easy solution is to use an If or switch by your init name XYZ123, and crete a class in if or switch case.
0
 

Author Comment

by:sbornstein2
ID: 17979234
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
        objClass.Startup
       
        'Finally CleanUp Access DB
        clsImportData.CleanUp
    Next
       
End Sub

the strEdit will have what I want to call with "cls"" in front
0
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 1200 total points
ID: 17981219
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():
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/b1545c3f-5cab-4c66-af6f-be9b7daa1131.asp

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

AlexNek has already suggested a big switch...
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
Make the most of your online learning experience.
Six Sigma Control Plans
Starting up a Project

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question