Solved

Dynamically call a class startup

Posted on 2006-11-17
4
164 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 85

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 85

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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Here we come across an interesting topic of coding guidelines while designing automation test scripts. The scope of this article will not be limited to QTP but to an overall extent of using VB Scripting for automation projects. Introduction Now…
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
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 …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

744 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now