CodeGuru Forums -
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic Newsletters VB Forums Developer.com


Newest CodeGuru.com Articles:

  • SQL Server Modeling Services with Microsoft Visual Studio 2010 Beta 2
  • Faltering Windows support
  • Internet Explorer 8 Click Clever Click Safe
  • Release Candidate 2 for ASP.NET MVC 2

  • Search CodeGuru:
     



    Go Back   CodeGuru Forums > Visual Basic Programming > Visual Basic 6.0 Programming
    FAQ Members List Calendar Search Today's Posts Mark Forums Read

    Visual Basic 6.0 Programming Ask questions about VB 6.0 (or earlier versions) or help others by answering their question.

    Reply
     
    Thread Tools Search this Thread Rate Thread Display Modes
      #1    
    Old November 20th, 2009, 10:39 AM
    AdamC AdamC is offline
    Junior Member
     
    Join Date: Nov 2009
    Posts: 1
    AdamC is an unknown quantity at this point (<10)
    Calling Class module from a variable

    hi im lookin at a way of improving part of my program, i currenly have multiple class modules for differnt programs which users use.

    at pressent the user selects the program they wish to run and it runs though a select case (as shown below) to find the class to call

    jobrun = databaserecord.rsselectjobrun.Fields("Jobname")

    Select Case jobrun

    Case "JOB1":

    Dim myclass As New JOB1

    Sum = CallByName(myclass, "runjob", VbMethod)

    Case "JOB2":

    Dim myclass1 As New JOB2

    Sum = CallByName(myclass1, "runjob", VbMethod)

    Case "JOB3":

    Dim myclass2 As New JOB3

    Sum = CallByName(myclass2, "runjob", VbMethod)

    and so forth

    is there a way to hold the class name as a variable and then call the "runjob" public sub in the class

    i have tired the below but i just get the error 'user-defind type not defined'

    Dim myclass As Object
    dim jobname as string

    jobname = "JOB1"

    Set myclass = New jobname

    Sum = CallByName(myclass, "runjob", VbMethod)

    Set myclass = Nothing

    I would be gratefull for any help on the matter or if you can think of a more productive way of solving this issue

    Many Thanks Adam
    Reply With Quote
      #2    
    Old November 20th, 2009, 12:22 PM
    WizBang WizBang is offline
    Super Moderator
    Power Poster
     
    Join Date: Dec 2001
    Posts: 6,166
    WizBang has much to be proud of (1500+) WizBang has much to be proud of (1500+) WizBang has much to be proud of (1500+) WizBang has much to be proud of (1500+) WizBang has much to be proud of (1500+) WizBang has much to be proud of (1500+) WizBang has much to be proud of (1500+) WizBang has much to be proud of (1500+) WizBang has much to be proud of (1500+) WizBang has much to be proud of (1500+) WizBang has much to be proud of (1500+)
    Re: Calling Class module from a variable

    The first thing that comes to mind is to put all public methods in one class. Then you can use the string to determine which method to execute.

    One other possibility might be to use CreateObject(), though I think your classes would then need to be compiled into one or more DLL files (separately from the exe). However, if I'm not mistaken, this would mean late binding.
    __________________
    Please remember to rate the posts and threads that you find useful.
    How can something be both new and improved at the same time?
    Reply With Quote
    Reply

    Bookmarks
    Go Back   CodeGuru Forums > Visual Basic Programming > Visual Basic 6.0 Programming


    Thread Tools Search this Thread
    Search this Thread:

    Advanced Search
    Display Modes Rate This Thread
    Rate This Thread:

    Posting Rules
    You may not post new threads
    You may not post replies
    You may not post attachments
    You may not edit your posts

    BB code is On
    Smilies are On
    [IMG] code is On
    HTML code is Off
    Forum Jump


    All times are GMT -5. The time now is 11:00 AM.



    Acceptable Use Policy


    The Network for Technology Professionals

    Search:

    About Internet.com

    Legal Notices, Licensing, Permissions, Privacy Policy.
    Advertise | Newsletters | E-mail Offers


    Powered by vBulletin® Version 3.7.3
    Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.