473,587 Members | 2,230 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Late Binding Question

Siv
hi,
I am converting an application that writes to an Excel spreadsheet and the
code trips the "option Strict" that I would like on because the parser says
"option Strict On disallows late binding", I am struggling to understand why
I am tripping this error.

This is the code that causes the problems:

XLApp.Goto("Mon thTitleTL") 'Goes to bookmark in sheet
r = XLApp.ActiveCel l.Row 'sets variable r equal
to the row of that cell
c = XLApp.ActiveCel l.Column 'Sets the c variable to
the column of that cell
For n = 0 To 11 'Process the 12 months of
data held in the T7Lines(n) collection
XLApp.Cells(r, c).Formula = T7Lines(n).Text MonthNumber
XLApp.Cells(r + 3, c).formula =
Format(T7Lines( n).RiskPointsTo tal, "0.0")
....
Next n

I don't get a) why this is classed as late binding? and b) what I do to stop
it other than turn off option strict which I don't want to do.

Any help appreciated.

Siv
Martley, Near Worcester, UK.

Jun 27 '08 #1
14 2020
"Siv" <g@removethiste xtsivill.comsch rieb
I don't get a) why this is classed as late binding?
Without seeing a variable declaration, it's impossible to see if it's
late bound execution.

and b) what I do
to stop it other than turn off option strict which I don't want to
do.
1. Project -Add reference -COM tab -Add "Microsoft Excel x.y
Object Library"
2. Declare variables, for example, "As Excel.Applicati on"

Then you are bound to the referenced Excel version on the target
machine.
Armin

Jun 27 '08 #2
Siv
Armin,
Vars as follows:

In the procedure that the code was taken from:

Dim n as integer = 0
Dim r as integer = 0

The XLApp var is declared at the top of the class as follows:
Private XLApp As XL.Application

At the start of the processing block that calls the procedure I copied here,
I test if XLApp is already open and if not open it:

If IsNothing(XLApp ) Then
XLApp = New XL.Application
End If

I hope this is what you need.

Siv

"Armin Zingler" <az*******@free net.dewrote in message
news:uQ******** ******@TK2MSFTN GP05.phx.gbl...
"Siv" <g@removethiste xtsivill.comsch rieb
>I don't get a) why this is classed as late binding?

Without seeing a variable declaration, it's impossible to see if it's
late bound execution.

>and b) what I do
to stop it other than turn off option strict which I don't want to
do.

1. Project -Add reference -COM tab -Add "Microsoft Excel x.y Object
Library"
2. Declare variables, for example, "As Excel.Applicati on"

Then you are bound to the referenced Excel version on the target
machine.
Armin
Jun 27 '08 #3
Siv
Armin,
Vars as follows:

In the procedure that the code was taken from:

Dim n as integer = 0
Dim r as integer = 0

The XLApp var is declared at the top of the class as follows:
Private XLApp As XL.Application

At the start of the processing block that calls the procedure I copied here,
I test if XLApp is already open and if not open it:

If IsNothing(XLApp ) Then
XLApp = New XL.Application
End If

I hope this is what you need.

Siv

"Armin Zingler" <az*******@free net.dewrote in message
news:uQ******** ******@TK2MSFTN GP05.phx.gbl...
"Siv" <g@removethiste xtsivill.comsch rieb
>I don't get a) why this is classed as late binding?

Without seeing a variable declaration, it's impossible to see if it's
late bound execution.

>and b) what I do
to stop it other than turn off option strict which I don't want to
do.

1. Project -Add reference -COM tab -Add "Microsoft Excel x.y Object
Library"
2. Declare variables, for example, "As Excel.Applicati on"

Then you are bound to the referenced Excel version on the target
machine.
Armin
Jun 27 '08 #4
Siv
Armin,

I added the Excel reference using the "Microsoft.Offi ce.Interop.Exce l"
reference in the Dot Net tab. Does adding that as a COM object work better
and if so why?

The version of Excel being referenced is 11.0.0.0 version as the client is
using Office 2003.

Siv

"Armin Zingler" <az*******@free net.dewrote in message
news:uQ******** ******@TK2MSFTN GP05.phx.gbl...
"Siv" <g@removethiste xtsivill.comsch rieb
>I don't get a) why this is classed as late binding?

Without seeing a variable declaration, it's impossible to see if it's
late bound execution.

>and b) what I do
to stop it other than turn off option strict which I don't want to
do.

1. Project -Add reference -COM tab -Add "Microsoft Excel x.y Object
Library"
2. Declare variables, for example, "As Excel.Applicati on"

Then you are bound to the referenced Excel version on the target
machine.
Armin
Jun 27 '08 #5
Siv
Armin,

I added the Excel reference using the "Microsoft.Offi ce.Interop.Exce l"
reference in the Dot Net tab. Does adding that as a COM object work better
and if so why?

The version of Excel being referenced is 11.0.0.0 version as the client is
using Office 2003.

Siv

"Armin Zingler" <az*******@free net.dewrote in message
news:uQ******** ******@TK2MSFTN GP05.phx.gbl...
"Siv" <g@removethiste xtsivill.comsch rieb
>I don't get a) why this is classed as late binding?

Without seeing a variable declaration, it's impossible to see if it's
late bound execution.

>and b) what I do
to stop it other than turn off option strict which I don't want to
do.

1. Project -Add reference -COM tab -Add "Microsoft Excel x.y Object
Library"
2. Declare variables, for example, "As Excel.Applicati on"

Then you are bound to the referenced Excel version on the target
machine.
Armin
Jun 27 '08 #6
Siv
Armin,
Sorry about the multiple posts, Windows Mail jus threw a wobbly and kept
refusing to send outbound then after a restart decided to send all the
attempts before I had chance to delete them.

I wanted to add that the XL reference comes from an "Imports" at the top of
the class:

Imports XL = Microsoft.Offic e.Interop.Excel

Then I do:
Private XLApp as XL.Application at class level.

Hope this makes sense?

Siv

"Armin Zingler" <az*******@free net.dewrote in message
news:uQ******** ******@TK2MSFTN GP05.phx.gbl...
"Siv" <g@removethiste xtsivill.comsch rieb
>I don't get a) why this is classed as late binding?

Without seeing a variable declaration, it's impossible to see if it's
late bound execution.

>and b) what I do
to stop it other than turn off option strict which I don't want to
do.

1. Project -Add reference -COM tab -Add "Microsoft Excel x.y Object
Library"
2. Declare variables, for example, "As Excel.Applicati on"

Then you are bound to the referenced Excel version on the target
machine.
Armin
Jun 27 '08 #7
Siv
Armin,
I changed the line:

rng = XLapp.Cells(She etRow, SheetCol)

to

rng = DirectCast(XLAp p.Cells(SheetRo w, SheetCol), XL.Range)

Which the parser is happy with; whether it works when I run it is another
question!

I will now try and figure how I apply that to the

XLApp.Cells(r + 3, c).formula = Format(T7Lines( n).RiskPointsTo tal, "0.0")

Lines??

I have temporarily changed the late binding error as a warning and when I do
that the green wavy line appears under the left side of the argument. I
still don't understand why the compiler thinks this is late bound?? As far
as I can see all the variables are determined so that r+3 and c are known
values? I never did get what all the fuss about late binding is?

Thanks,

Siv
"Armin Zingler" <az*******@free net.dewrote in message
news:ew******** ******@TK2MSFTN GP02.phx.gbl...
"Siv" <g@removethiste xtsivill.comsch rieb
>Armin,

I added the Excel reference using the
"Microsoft.Off ice.Interop.Exc el" reference in the Dot Net tab. Does
adding that as a COM object work better and if so why?

Did you already have that reference before asking, or did you just add
it now? Inferred from your question, I thought you did not have any
reference yet. Obviously the PIAs (primary interop assemblies) are
installed on your machine. In this case, it's the preferred way instead
of the COM reference. The PIAs are taylor-made by the manufacturer of
the COM component (Excel). Otherwise, when setting the COM reference,
the Interop assembly is created by a standardized COM-Import procedure
that possibly doesn't fit 100% perfect and is recreated in every project
and every time you set a reference to the COM component.

Assuming that you have a reference to the assembly, the problem
is probably because the type of the default property of a range object
is "Object". Not every object has a property "Formula". Therefore the
error message. You'll have to cast it to the expected type. I don't know
it by heart; something like

Directcast(XLAp p.Cells(r, c), DestinationType ).Formula ....
Armin

Jun 27 '08 #8
Siv
Armin,

This seems to pacify the compiler:
DirectCast(XLAp p.Cells(r, c), XL.Range).Formu la = T7Lines(n).Text MonthNumber

I will see if the program runs as expected after I have corrected all
sections that need amending.

I tried

Siv

"Siv" <g@removethiste xtsivill.comwro te in message
news:C7******** *************** ***********@mic rosoft.com...
Armin,
I changed the line:

rng = XLapp.Cells(She etRow, SheetCol)

to

rng = DirectCast(XLAp p.Cells(SheetRo w, SheetCol), XL.Range)

Which the parser is happy with; whether it works when I run it is another
question!

I will now try and figure how I apply that to the

XLApp.Cells(r + 3, c).formula = Format(T7Lines( n).RiskPointsTo tal, "0.0")

Lines??

I have temporarily changed the late binding error as a warning and when I
do that the green wavy line appears under the left side of the argument.
I still don't understand why the compiler thinks this is late bound?? As
far as I can see all the variables are determined so that r+3 and c are
known values? I never did get what all the fuss about late binding is?

Thanks,

Siv
"Armin Zingler" <az*******@free net.dewrote in message
news:ew******** ******@TK2MSFTN GP02.phx.gbl...
>"Siv" <g@removethiste xtsivill.comsch rieb
>>Armin,

I added the Excel reference using the
"Microsoft.Of fice.Interop.Ex cel" reference in the Dot Net tab. Does
adding that as a COM object work better and if so why?

Did you already have that reference before asking, or did you just add
it now? Inferred from your question, I thought you did not have any
reference yet. Obviously the PIAs (primary interop assemblies) are
installed on your machine. In this case, it's the preferred way instead
of the COM reference. The PIAs are taylor-made by the manufacturer of
the COM component (Excel). Otherwise, when setting the COM reference,
the Interop assembly is created by a standardized COM-Import procedure
that possibly doesn't fit 100% perfect and is recreated in every project
and every time you set a reference to the COM component.

Assuming that you have a reference to the assembly, the problem
is probably because the type of the default property of a range object
is "Object". Not every object has a property "Formula". Therefore the
error message. You'll have to cast it to the expected type. I don't know
it by heart; something like

Directcast(XLA pp.Cells(r, c), DestinationType ).Formula ....
Armin

Jun 27 '08 #9

"Siv" <g@removethiste xtsivill.comwro te in message
news:B3******** *************** ***********@mic rosoft.com...
Armin,

This seems to pacify the compiler:
DirectCast(XLAp p.Cells(r, c), XL.Range).Formu la =
T7Lines(n).Text MonthNumber

I will see if the program runs as expected after I have corrected all
sections that need amending.

I tried

Siv

"Siv" <g@removethiste xtsivill.comwro te in message
news:C7******** *************** ***********@mic rosoft.com...
>Armin,
I changed the line:

rng = XLapp.Cells(She etRow, SheetCol)

to

rng = DirectCast(XLAp p.Cells(SheetRo w, SheetCol), XL.Range)

Which the parser is happy with; whether it works when I run it is another
question!

I will now try and figure how I apply that to the

XLApp.Cells( r + 3, c).formula = Format(T7Lines( n).RiskPointsTo tal, "0.0")

Lines??

I have temporarily changed the late binding error as a warning and when I
do that the green wavy line appears under the left side of the argument.
I still don't understand why the compiler thinks this is late bound?? As
far as I can see all the variables are determined so that r+3 and c are
known values? I never did get what all the fuss about late binding is?

Thanks,

Siv
"Armin Zingler" <az*******@free net.dewrote in message
news:ew******* *******@TK2MSFT NGP02.phx.gbl.. .
>>"Siv" <g@removethiste xtsivill.comsch rieb
Armin,

I added the Excel reference using the
"Microsoft.O ffice.Interop.E xcel" reference in the Dot Net tab. Does
adding that as a COM object work better and if so why?

Did you already have that reference before asking, or did you just add
it now? Inferred from your question, I thought you did not have any
reference yet. Obviously the PIAs (primary interop assemblies) are
installed on your machine. In this case, it's the preferred way instead
of the COM reference. The PIAs are taylor-made by the manufacturer of
the COM component (Excel). Otherwise, when setting the COM reference,
the Interop assembly is created by a standardized COM-Import procedure
that possibly doesn't fit 100% perfect and is recreated in every project
and every time you set a reference to the COM component.

Assuming that you have a reference to the assembly, the problem
is probably because the type of the default property of a range object
is "Object". Not every object has a property "Formula". Therefore the
error message. You'll have to cast it to the expected type. I don't know
it by heart; something like

Directcast(XL App.Cells(r, c), DestinationType ).Formula ....
Armin

You were asking about why late binding is "bad". When you late bind there
is a perfomance penalty to pay for each call. Since the compiler does not
know what type of object is being used until runtime it must each time
determine whether or not the property, function or subroutine is valid for
the target object at runtime. This takes time.

There is also the possiblity that the object at runtime will not support the
call. This will result in an exception which can be trapped using try -
catch but again this is very costly in comparison to an early binding call.

So really two reason not to use late binding if you can. One performance
and second program integrity.

LS

Jun 27 '08 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
7923
by: JD Kronicz | last post by:
Hi .. I have an issue I have been beating my head against the wall on for some time. I am trying to use late binding for MS graph so that my end users don't have to worry about having the right version of the MS Graph type library. Up until now I have been walking them through the process of setting the references to include their version...
9
10404
by: Zlatko Matić | last post by:
I was reading about late binding, but I'm not completely sure what is to be done in order to adjust code to late binding... For example, I'm not sure if this is correct: early binding: Dim ws As DAO.Workspace Dim db As DAO.Database Dim qdf As DAO.QueryDef Dim rs As DAO.Recordset
8
1534
by: scorpion53061 | last post by:
I am sorry for this but I am not getting an answer elsewhere so I thought I would try here. It seems the safer way to go prior to deployment is to change my early binding to late binding to prevent lots of issues occuring, especially those on Office versions other than mine. (I have 2003). such as Public WordApp As Object =...
5
2038
by: eBob.com | last post by:
In another thread VJ made me aware of Tag. Fantastic! I've been wanting this capability for a long time. But it seems that I cannot use it with Option Strict On. In an event handler I have ... Private Sub chkbxSelI_Click(ByVal sender As Object, ByVal e As System.EventArgs) MsgBox("bingo for number " & sender.Tag.ToString) End Sub
30
2809
by: lgbjr | last post by:
hi All, I've decided to use Options Strict ON in one of my apps and now I'm trying to fix a late binding issue. I have 5 integer arrays: dim IA1(500), IA2(500), IA3(500), IA4(500), IA5(500) as integer The integers in these arrays are actually pointers to different columns of data in a text file.
6
1884
by: Tim Roberts | last post by:
I've been doing COM a long time, but I've just come across a behavior with late binding that surprises me. VB and VBS are not my normal milieux, so I'm hoping someone can point me to a document that describes this. Here's the setup. We have a COM server, written in Python. For completeness, here is the script: ----- testserver.py...
21
3073
by: ManningFan | last post by:
I need to use late binding in a project because it's company standard to not include references which aren't MS defaults, so I can't add the scripting runtime. I need to be able to search folders (and sub-forders) for a file name, and then copy the file to a specified directory (at the moment it's C:\TempCD but that will change later. ...
6
3100
by: Stephany Young | last post by:
Using VS2005 and VB.NET and given a Windows Forms application with a single form (Form1) with 2 buttons (Button1 and Button2), I am attempting to instantiate an instance of Excel utilising late binding. The pertinent code is shown below. The business rules are: 1. If an instance of Excel is already running then use the equivalent of...
4
2598
by: =?Utf-8?B?Y2xhcmE=?= | last post by:
Hi all, what is the difference between the late binding and reflection? clara -- thank you so much for your help
0
7915
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7843
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8205
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8339
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7967
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6619
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
2347
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1452
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1185
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.