views:

18

answers:

1

Hi, I am writing an application in Visual Basic 2010 Express.

I have two objects of a class from a driver DLL that is provided to me. They have some of their own subroutines that I'd like to call, and I'd like an easy way to toggle between them.

Instead of writing a whole bunch of code like this:

selected = x
...
If selected = x then 
    DriverInstanceX.DoSomething() 
Else If Selected = y then 
    DriverInstanceY.DoSomething()
Endif

I would like to do this:

Bob = (some reference to X - NOT a copy of X!)
...
Bob.DoSomething()
Bob.DoSomethingElse()

I'm sure this is really easy - I am just not sure where to look.

Thanks for any help!

A: 

' set the object based on what was selected first, here...

Dim selectedDriverInstance = new DriverObject

' now you can run the method without checking for each as selected was already set. selectedDriverInstance.DoSometng()

Cool?

Of course, DriverObject can be the instance x or instance y depending on what u set it to, do the assignment there and set it to our fixed name object selectedDriverInstance. this way you can do everything using selectedDriverInstance as it is set to either instance x or instance y already, get me?

Erx_VB.NExT.Coder
Edited/updated, look above.
Erx_VB.NExT.Coder
OK, I suspected this would work but I wasn't totally sure. I'll have to just try it out once my program is complete enough to actually run in a functional way. Thanks!
evilspoons
Well, lye me know how it goes and if it doesn't work feel free to send me the class and I'll restructure it for you. If it works out don't forget to mark as accepted answer :)
Erx_VB.NExT.Coder