Option Strict On disallows late binding.

H

Heinz

Hi all,

I use VB.net 2003 and want to export data to Excel. Target PCs still
have Office 2000 so I could not use Microsofts PIAs. Instead I use the
included Excel 10 COM DLL from Microsoft. Everything works fine.

Now I want to sign my application with a strong name. Therefore I also
need to sign all DLLs. So I searched through the web and found
information that I need to use tlbimp, and the source file is
'xl5en32.olb'. Now this also works fine.

But then I want to set options strict ON and I only receive this
error:
Option Strict On disallows late binding.

I've found that I need to use DirectCast but this does not seem to
work :-( Is there any documentation about exporting data to excel
while using strong names and option strict on?
 
C

Chris

Heinz said:
Hi all,

I use VB.net 2003 and want to export data to Excel. Target PCs still
have Office 2000 so I could not use Microsofts PIAs. Instead I use the
included Excel 10 COM DLL from Microsoft. Everything works fine.

Now I want to sign my application with a strong name. Therefore I also
need to sign all DLLs. So I searched through the web and found
information that I need to use tlbimp, and the source file is
'xl5en32.olb'. Now this also works fine.

But then I want to set options strict ON and I only receive this
error:
Option Strict On disallows late binding.

I've found that I need to use DirectCast but this does not seem to
work :-( Is there any documentation about exporting data to excel
while using strong names and option strict on?

In what code does DirectCast not work? CType() is another less strict
version of directcast, it may solve your problem.

Chris
 
G

Greg Burns

Heinz said:
But then I want to set options strict ON and I only receive this
error:
Option Strict On disallows late binding.

I've found that I need to use DirectCast but this does not seem to
work :-( Is there any documentation about exporting data to excel
while using strong names and option strict on?

I've skirted this issue by moving my Excel late binding stuff into a
separate class files that has Option Strict Off.

I have code like this (see below), that I have not figured out yet how to
use Option Strict On w/ DirectCast. :(

Dim objSheet As Excel.Worksheet
....
objSheet.Cells(i, j).NumberFormat = "@" 'Option Strict On disallows late
binding error here

I'm interested in hearing others ideas as well.

Greg
 
G

Greg Burns

Greg Burns said:
I have code like this (see below), that I have not figured out yet how to
use Option Strict On w/ DirectCast. :(

Dim objSheet As Excel.Worksheet
...
objSheet.Cells(i, j).NumberFormat = "@" 'Option Strict On disallows late
binding error here

Nevermind...

DirectCast(objSheet.Cells(i, j), Excel.Range).NumberFormat = "@"

That does seems to be what I needed to allow Option Strict On. :)

Greg
 
H

Heinz

In what code does DirectCast not work? CType() is another less strict
version of directcast, it may solve your problem.

Hi Chris,

so I now modified my code and could save it even with options strict
on. But the export does not work.

I've now added the following code:

Dim XLApplication As Excel.Application
Dim XLWorkbook As Excel.Workbook
Dim XLworkbooks As Excel.Workbooks
XLApplication = CType(CreateObject("Excel.Application"),
Excel.Application)
XLworkbooks = DirectCast(XLApplication.Workbooks, Excel.Workbooks)
XLWorkbook = DirectCast(XLworkbooks.Add, Excel.Workbook)

Application crashes on second executed statement 'XLWorkbooks = ....'
with Error message 'Member not found'.....?? (Same if I use CTYPE
instead of DirectCast) So I'm also not sure whether it was correct to
sign the specified .olb file and use this one then...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top