tags:

views:

17

answers:

2

Late binding is not allowed and that's how we want it.

Depending on whether our program is running on a LAN or the Internet, we need to dim an object as one of two types. We use an if...then statement to ascertain whether or not we are running on a LAN or the Internet.

When we declare our object inside the if...then statement, we have declared in the wrong scope and cannot use the object. When we declare it as an 'Object' type and use DirectCast inside an if...then statement, we receive a late binding error.

How can we get around this problem without turning off Option Strict?

+2  A: 

I haven't used vb.net - so consider the source. But can't you declare each of the types to be a subclass of another type, and have that superclass type as the declared type of your object?

Carl Manaster
A: 

As far as I know that's essentially what I'm doing when I try to use the Object class for variable initialization. However, when I attempt a DirectCast to narrow it down to the type I need, it still throws the late binding error.

stephen falken
Carl is talking about using [inheritance](http://support.microsoft.com/kb/307222). You shouldn't need to cast at all. Can't you put all the functionality you need in the superclass (the class you inherit from)?
MarkJ