View Single Post
  #8   Report Post  
Posted to microsoft.public.excel.programming
GS[_2_] GS[_2_] is offline
external usenet poster
 
Posts: 3,514
Default Type Mismatch error when trying to generically set ComboBox to a ComboBox variable

bllittle pretended :
On Apr 7, 7:55*pm, GS wrote:
bllittle wrote on 4/7/2011 :
For example, if I create a variant and assign a worksheet to it, I
don't get the contextual methods and properties specific to a
worksheet if I use the variable in the code. But if I declare a series
of variables, ending by typing them As Worksheet, it would appear
early binding is taking place as the contextual methods and properties
work just fine. I wonder if declaring object type variables behaves
differently than data type variables.


It doesn't work that way. For example, the only variable in the
following line that 'actually' is String type is the last one.

Dim strTargetWorksheet, strTargetCmb, strRecSQL, strWorkbookName,
strWorkbookLoc, strFullLocValue As String


I understand what you're saying and is why I specified it may be
different for object type variables in contrast to data type
variables. I didn't happen to have that many in the code I posted for
you to excerpt, but the following does work for early binding:

Dim wks1, wks2, wks3 As Worksheet


That's because a Variant type CAN BE ANYTHING, INCLUDING AN OBJECT!

If you didn't declare the last one they'd all still work anyway. Fact
is, the first 2 are being handled by VBA as worksheet objects while the
3rd one doesn't require VBA to evaluate it as a worksheet object
because you declared it as such. Technically, you could always just Dim
vars without ever declaring type and VBA will not object. Problem is
that it adds horrific resources overhead (Variant types require more
memory than most other types, and VBA has to evaluate it to determine
how to handle it!) to your project for VBA to have to determine the
type as code executes.


I can (and have countless times) reference wks1 or wks2 and have
contextual properties and and methods specific to the Worksheet object
assist me in coding; that wouldn't be the case if they were being
viewed as Variant because there wouldn't be any specific context to
narrow the properties and methods down to.

I'm not trying to be argumentative or anything and I appreciate your
insight on what I'd clearly been misinformed on in regards to data
type variable declarations. Just pointing out there are apparently
other situations where it does work that way.


As I said, Variant types will always work regardless of what you use
them for.<g


Kind regards,
Bruce


--
Garry

Free usenet access at http://www.eternal-september.org
ClassicVB Users Regroup! comp.lang.basic.visual.misc