?
Solved

Dynamically call a class startup

Posted on 2006-11-17
4
Medium Priority
?
173 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
  • 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In this post we will learn different types of Android Layout and some basics of an Android App.
In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
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 …
Loops Section Overview

850 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