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):
First question: Is there a better way of doing this?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
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




Reply With Quote