Solved

Dynamically call a class startup

Posted on 2006-11-17
4
169 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 100 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 300 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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

This article will show, step by step, how to integrate R code into a R Sweave document
A short article about a problem I had getting the GPS LocationListener working.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

690 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