473,544 Members | 2,002 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Option Strict On related problem.

Hello
After reading yesterday's thread on performance of C# and
vb.net i've just turn it on my solution and spent 2 hours
correcting the errors :)

I have a problem i don't how to fix i have a class that
export data to a Excel Workbook.
I get 2 types of errors : Option Strict On disallows
implicit conversions from 'System.Object'
to 'Excel.Workshee t' and Option Strict On disallows late
binding.

This how the excel objects are defined :
Dim objPrograma As New Excel.Applicati on
Dim objLivro As Excel.Workbook = objPrograma.Wor kbooks.Add
Dim objFolha As Excel.Worksheet = objPrograma.Act iveSheet

The following raise errors:
objLivro.Sheets ("Folha1").n ame = "Português"
objLivro.Sheets ("Folha2").dele te()

And also:
objLivro.Sheets ("English").act ivate()
objFolha = objPrograma.Act iveSheet()

For example the following works ok:
objFolha.Range( "a4").VerticalA lignment =
Excel.XlHAlign. xlHAlignCenter
objFolha.Range( "a4").Horizonta lAlignment =
Excel.XlHAlign. xlHAlignCenter
Any suggestion how to solve this matter, would be most
welcome thanks!

Kind Regards
Jorge Cavalheiro
Nov 20 '05 #1
3 1678
Jorge,
After reading yesterday's thread on performance of C# and
vb.net i've just turn it on my solution and spent 2 hours
correcting the errors :)
Glad you made the change - it's always a good idea to switch "Option Strict
On" all the time. Apart from performace gains because the compiler can
optimise better, it should also give you a better understanding of how
different types convert to and from other types. The better you know how
this process works, the more optimzations you can use in your own code
because you can tweak your design.
The following raise errors:
objLivro.Sheet s("Folha1").nam e = "Português"
objLivro.Sheet s("Folha2").del ete()
As mentioned, Option Strict ON does not allow late binding. I'm not
familliar with Excel's object model, but I suspect that
"objLivro.Sheet s("Folha1")" returns an Object, not a specific type.

Try wrapping the call in a call to "ctype" or "directcast " like this

---------------

directCast(objL ivro.Sheets("Fo lha1"), Excel.WorkSheet ).name = "Português"
directCast(objL ivro.Sheets("Fo lha2"), Excel.WorkSheet ).delete()

---------------
objLivro.Sheet s("English").ac tivate()
objFolha = objPrograma.Act iveSheet()


Try the following
---------------

directCast(objL ivro.Sheets("En glish"), Excel.WorkSheet ).activate()
objFolha = directCast(objP rograma.ActiveS heet, Excel.WorkSheet )

---------------

Obviously, change the type"Excel.Work Sheet" to whatever type you are
expecting. I would also consider using a With Block or a local variable to
hold a strongly typed reference to the objcts you are accessing - this way
you cut down the number of calls to DirectCast

HTH,

Trev.
Nov 20 '05 #2
"Jorge Cavalheiro" <de*******@yaho o.com> schrieb

I have a problem i don't how to fix i have a class that
export data to a Excel Workbook.
I get 2 types of errors : Option Strict On disallows
implicit conversions from 'System.Object'
to 'Excel.Workshee t' and Option Strict On disallows late
binding.

This how the excel objects are defined :
Dim objPrograma As New Excel.Applicati on
Dim objLivro As Excel.Workbook = objPrograma.Wor kbooks.Add
Dim objFolha As Excel.Worksheet = objPrograma.Act iveSheet

The following raise errors:
objLivro.Sheets ("Folha1").n ame = "Português"
I assume Sheets only contains Sheet objects:

Directcast(objL ivro.Sheets("Fo lha1"), Excel.Sheet).na me = "Português"
objLivro.Sheets ("Folha2").dele te()
Directcast(objL ivro.Sheets("Fo lha2"), Excel.Sheet).de lete

And also:
objLivro.Sheets ("English").act ivate()
objFolha = objPrograma.Act iveSheet()

Use directcast also.
--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #3
Thanks its working fine now

Kind Regards
Jorge
-----Original Message-----
"Jorge Cavalheiro" <de*******@yaho o.com> schrieb

I have a problem i don't how to fix i have a class that
export data to a Excel Workbook.
I get 2 types of errors : Option Strict On disallows
implicit conversions from 'System.Object'
to 'Excel.Workshee t' and Option Strict On disallows late binding.

This how the excel objects are defined :
Dim objPrograma As New Excel.Applicati on
Dim objLivro As Excel.Workbook = objPrograma.Wor kbooks.Add Dim objFolha As Excel.Worksheet = objPrograma.Act iveSheet
The following raise errors:
objLivro.Sheets ("Folha1").n ame = "Português"
I assume Sheets only contains Sheet objects:

Directcast(obj Livro.Sheets("F olha1"), Excel.Sheet).na me

= "Português"
objLivro.Sheets ("Folha2").dele te()


Directcast(obj Livro.Sheets("F olha2"), Excel.Sheet).de lete

And also:
objLivro.Sheets ("English").act ivate()
objFolha = objPrograma.Act iveSheet()

Use directcast also.
--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

.

Nov 20 '05 #4

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

Similar topics

9
2124
by: Microsoft News | last post by:
I have a project that was created all with Option Strict OFF. Works great, not a problem with it. But if I turn Option Strict ON then I get a LOT of errors. My question, should I even care about Option Strict? What advantages do I get with Option Strict On? Does better type statement make my code run faster? If anyone knows THE...
13
3240
by: Cor | last post by:
Hi Option Strict gurus, Because of the so much given advises here to use Option Strict I did try to use that. But it gives an error and I don't know how to resolve that. The message is that Option Strict disallowes late binding. So how to do it then? The statement is from an example somewhere on MSDN (And don't ask why I use the Ax version...
11
2096
by: Daylor | last post by:
hi. im using option strict on. im doing in ,from the simple reason ,to be warn when there are implict conversion like string to int ,int to string. BUT. the price ,(now i see ), is very bad. if i have class CCar and interface ICar when im doing this : ICar = new CCar
17
4465
by: David | last post by:
Hi all, I have the following problem: my program works fine, but when I add option strict at the top of the form, the following sub fails with an error that option strict does not allow late binding. What should I do? Public Sub MyMnuHandler(ByVal sender As Object, ByVal e As System.EventArgs) If sender.checked = True Then...
4
1348
by: zacks | last post by:
A common programming technique I use in VB is making a collection of structures. But if Option Strict is on (which I would prefer), the .Add that adds the structure to the collection is flagged with a compiler error (invalid type conversion). Is there a way to use a collection of structures WITH the Option Strict On?
15
1533
by: guy | last post by:
when i first started using .net (beta 1) i came across option strict and thought hey this could be really good, and since then have always turned it on, most people here seem to agree that this is a good thing. i have now been asked to debug a vb2005 web app for 3 weeks and there is no mention of option strict in it, (there are also no...
13
2308
by: C. Moya | last post by:
I fully expected the lack of a way to set Option Strict globally to be fixed in SP1. I can't seem to figure out if it has been fixed or not. It still seems we have to add the declaration at the top of each and every single code module. Am I missing something here? -- -C. Moya www.cmoya.com
6
423
by: Rob | last post by:
I have employed a "Singleton mode" of programming for this project. I have a class that exposes some properties of the class "Sample" to other forms.... If I set Option Strict On, I get many "Option Strict On disallows late binding" errors (see below) How might I fix this ?
4
2041
by: rebeccatre | last post by:
please help me with this, <style> #a, option.message {background-color: green; color: white;} #b, option.message {background-color: yellow; color: black;} </style> <select id="thisselect"> <option id="thisone" class="message">THANK YOU</option> </select>
0
7763
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...
0
7701
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...
0
5901
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
5289
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...
0
4908
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3404
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...
0
3402
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1834
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
0
654
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.