PC Review


Reply
Thread Tools Rate Thread

Compiling and Late Binding

 
 
Tim Childs
Guest
Posts: n/a
 
      16th Dec 2011
Hi

in the few lines of code below which was from Dave Petersen and Joe U, the
use of the Excel command ForceFullCalculation does not produce a standard
compilation error (due to late binding apparently), whereas it would if it
was just
Thisworkbook.ForceFullCalculation

If Val(Application.Version) > 11 Then
Set oWkBk = ThisWorkbook
oWkBk.ForceFullCalculation = True
Debug.Print "Running forced calculation"
End If

Can someone explain briefly WHY late binding applies in this area?

Many thanks

Tim

 
Reply With Quote
 
 
 
 
Dave Peterson
Guest
Posts: n/a
 
      16th Dec 2011
Just my thoughts -- could be completely wrong technically. But it satisfies my
curiosity <vbg>.

Excel knows all the properties and methods for ThisWorkbook just like it knows
all the properties and methods for a Range object.

But it has no idea what you're doing with a variable declared as an Object.

So no matter what version you're using if you use ThisWorkbook, excel knows --
you can't fool it.

But if you use the Object variable, excel doesn't know or care until the code
actually runs.

On 12/16/2011 05:02, Tim Childs wrote:
> Hi
>
> in the few lines of code below which was from Dave Petersen and Joe U, the use
> of the Excel command ForceFullCalculation does not produce a standard
> compilation error (due to late binding apparently), whereas it would if it was just
> Thisworkbook.ForceFullCalculation
>
> If Val(Application.Version) > 11 Then
> Set oWkBk = ThisWorkbook
> oWkBk.ForceFullCalculation = True
> Debug.Print "Running forced calculation"
> End If
>
> Can someone explain briefly WHY late binding applies in this area?
>
> Many thanks
>
> Tim


--
Dave Peterson
 
Reply With Quote
 
Martin Brown
Guest
Posts: n/a
 
      16th Dec 2011
On 16/12/2011 11:02, Tim Childs wrote:
> Hi
>
> in the few lines of code below which was from Dave Petersen and Joe U,
> the use of the Excel command ForceFullCalculation does not produce a
> standard compilation error (due to late binding apparently), whereas it
> would if it was just
> Thisworkbook.ForceFullCalculation
>
> If Val(Application.Version) > 11 Then
> Set oWkBk = ThisWorkbook
> oWkBk.ForceFullCalculation = True
> Debug.Print "Running forced calculation"
> End If
>
> Can someone explain briefly WHY late binding applies in this area?


Excel doesn't bother to check if the object oWkBk can execute the
statement "ForceFullCalculation = True" until it reaches that line.

Protected with this code you can insert completely invalid invocations
of non-existent and fictitious methods of oWkBk eg.

oWkBk.Zork Xyzzy = "Hello Sailor"

It will give a runtime error 438 "Object doesn't support property of
method" if you ever execute the line but not until. So it is quite a
clever way to hide Version related incompatibilities from the compiler.

I am pretty sure no versions of XL ever supported the Zork method.
(a prehistoric text based adventure game)

Regards,
Martin Brown
 
Reply With Quote
 
Tim Childs
Guest
Posts: n/a
 
      16th Dec 2011
Hi Martin and Dave

MANY thanks for those responses - interesting to hear what the experts get
up to with overcoming version incompatibilities.

best wishes

Tim

("Qu: Upgrades - Progress isn't all what it's cracked up to be?").

"Martin Brown" <|||newspam|||@nezumi.demon.co.uk> wrote in message
news:jcfdh7$a8l$(E-Mail Removed)...
> On 16/12/2011 11:02, Tim Childs wrote:
>> Hi
>>
>> in the few lines of code below which was from Dave Petersen and Joe U,
>> the use of the Excel command ForceFullCalculation does not produce a
>> standard compilation error (due to late binding apparently), whereas it
>> would if it was just
>> Thisworkbook.ForceFullCalculation
>>
>> If Val(Application.Version) > 11 Then
>> Set oWkBk = ThisWorkbook
>> oWkBk.ForceFullCalculation = True
>> Debug.Print "Running forced calculation"
>> End If
>>
>> Can someone explain briefly WHY late binding applies in this area?

>
> Excel doesn't bother to check if the object oWkBk can execute the
> statement "ForceFullCalculation = True" until it reaches that line.
>
> Protected with this code you can insert completely invalid invocations of
> non-existent and fictitious methods of oWkBk eg.
>
> oWkBk.Zork Xyzzy = "Hello Sailor"
>
> It will give a runtime error 438 "Object doesn't support property of
> method" if you ever execute the line but not until. So it is quite a
> clever way to hide Version related incompatibilities from the compiler.
>
> I am pretty sure no versions of XL ever supported the Zork method.
> (a prehistoric text based adventure game)
>
> Regards,
> Martin Brown


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off



Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:02 PM.