473,708 Members | 2,411 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 2033
"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
7937
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 of MS Graph library. My problem is that I can not seem to get the syntax correct .. or perhaps...
9
10422
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
1541
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 = CreateObject("Word.Application") Public oDoc As Object = CreateObject("Word.Document")
5
2047
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
2826
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
1893
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 ----- import pythoncom
21
3089
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. All I have so far is the following, I believe my main issue to tackle is to figure out how to get to...
6
3104
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 GetObject to obtain a reference to that instance, and, when finished, leave that instance running.
4
2611
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
8697
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9290
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9061
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
9001
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6615
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4454
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3151
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
2
2508
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2097
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.