Results 1 to 2 of 2

Thread: Using CreateObject with CallByName

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2002
    Location
    Madrid
    Posts
    9

    Using CreateObject with CallByName

    I'm pretty new to using classes so I would appreciate some help.
    I'm using VB6 and I have the following problem:

    I need to connect with various instruments via the serial port.
    Each instrument has a different set of commands to perform a
    number of standard tasks, all instruments are capable of
    performing the same standard tasks (methods).

    I have created a class for each instrument type: e.g.
    clsInstrument1, clsInstrument2 etc..

    and each class has the same methods: e.g. CheckCommunications, CloseConnection...

    My idea is to have just one select case statement to choose the
    instrument class, create an object and then use the same code
    for all instrument classes.

    This is what I have so far in the calling routine (pseudo-code):

    Code:
    dim objInstrument as Object
    
    Select Case iInstrumentClass
    Case 1
       Set objInstrument = CreateObject(clsInstrument1)
    Case 2
       Set objInstrument = CreateObject(clsInstrument2)
    End Select
    
    CallByName objInstrument , CheckCommunications, VbMethod
    CallByName objInstrument , CloseConnection, VbMethod
    First question: Is there a better way of doing this?
    Second question: If this way of doing things is reasonable, do I
    have to put the instrument classes into an ActiveX DLL in order
    to access them with the CreateObject function?

    Many Thanks

  2. #2

    Thread Starter
    New Member
    Join Date
    Jan 2002
    Location
    Madrid
    Posts
    9

    [RESOLVED] Using CreateObject with CallByName

    I found the answer to this question in the following thread:

    http://www.vbforums.com/showthread.p...ss+dynamically

    If only I knew the right keywords to search for every time I have a problem!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width