473,890 Members | 1,430 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Late binding errors with Option Strict ?

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(By Val sender As Object, ByVal e As System.EventArg s)

If sender.checked = True Then sender.checked = False Else sender.checked = True

End Sub

Nov 21 '05
17 4501
"Cor Ligthert [MVP]" <no************ @planet.nl> wrote in message
news:uz******** ******@TK2MSFTN GP10.phx.gbl...
Herfried,
Item.Checked = Not Item.Checked
///
New one, from the German groups or by yourself.

:-)


Sorry, I don't follow you...

That = Not item.Checked is something I never saw in these newsgroups.

Is it something you come with or did you see it in a German newsgroup.

Cor


Cor,

I've been using that for years in VB Classic. It's a fairly old bethod of
toggling booleans. I posted the same approach just minutes before
Herfried's post.

--
Al Reid
Nov 21 '05 #11
Hi Herfried,

http://mindview.net/WebLog/log-0025

I'm still a great fan of Option Strict On, though ;-)

--

Best regards,

Carlos J. Quintero

MZ-Tools: Productivity add-ins for Visual Studio .NET, VB6, VB5 and VBA
You can code, design and document much faster.
Free resources for add-in developers:
http://www.mztools.com
"Herfried K. Wagner [MVP]" <hi************ ***@gmx.at> escribió en el mensaje
news:Oy******** ********@TK2MSF TNGP14.phx.gbl. ..
"ng" <t_*****@yahoo. com> schrieb:
Don't use option strict


LOL!

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #12
Carlos,
I normally run with Option Strict On, however Option Strict Off is very
useful some times. For example when dealing with COM interop, especially COM
objects written for VBScript where all return values were defined as
Variant...

I'm looking forward to Partial Classes in VB 2005 as they will allow me to
isolate just the parts of my class that needs Option Strict Off to its own
source file!

Jay
"Carlos J. Quintero [VB MVP]" <ca*****@NOSPAM sogecable.com> wrote in message
news:eu******** ******@TK2MSFTN GP14.phx.gbl...
| Hi Herfried,
|
| http://mindview.net/WebLog/log-0025
|
| I'm still a great fan of Option Strict On, though ;-)
|
| --
|
| Best regards,
|
| Carlos J. Quintero
|
| MZ-Tools: Productivity add-ins for Visual Studio .NET, VB6, VB5 and VBA
| You can code, design and document much faster.
| Free resources for add-in developers:
| http://www.mztools.com
|
|
| "Herfried K. Wagner [MVP]" <hi************ ***@gmx.at> escribió en el
mensaje
| news:Oy******** ********@TK2MSF TNGP14.phx.gbl. ..
| > "ng" <t_*****@yahoo. com> schrieb:
| >> Don't use option strict
| >
| > LOL!
| >
| > --
| > M S Herfried K. Wagner
| > M V P <URL:http://dotnet.mvps.org/>
| > V B <URL:http://classicvb.org/petition/>
|
|
Nov 21 '05 #13
Carlos,
This just in ;-)

http://www.panopticoncentral.net/arc.../02/10428.aspx

Jay

"Carlos J. Quintero [VB MVP]" <ca*****@NOSPAM sogecable.com> wrote in message
news:eu******** ******@TK2MSFTN GP14.phx.gbl...
| Hi Herfried,
|
| http://mindview.net/WebLog/log-0025
|
| I'm still a great fan of Option Strict On, though ;-)
|
| --
|
| Best regards,
|
| Carlos J. Quintero
|
| MZ-Tools: Productivity add-ins for Visual Studio .NET, VB6, VB5 and VBA
| You can code, design and document much faster.
| Free resources for add-in developers:
| http://www.mztools.com
|
|
| "Herfried K. Wagner [MVP]" <hi************ ***@gmx.at> escribió en el
mensaje
| news:Oy******** ********@TK2MSF TNGP14.phx.gbl. ..
| > "ng" <t_*****@yahoo. com> schrieb:
| >> Don't use option strict
| >
| > LOL!
| >
| > --
| > M S Herfried K. Wagner
| > M V P <URL:http://dotnet.mvps.org/>
| > V B <URL:http://classicvb.org/petition/>
|
|
Nov 21 '05 #14
> http://mindview.net/WebLog/log-0025

I'm still a great fan of Option Strict On, though ;-)


I mainly use option strict to catch ansi/unicode mismatches, otherwise,
I do agree. I think in vb it's different than C++, vb can be so "lazy" that option
strict is useful if only to remind oneself what is going on, especially if
one is migrating from vb6 to vb.net.
Nov 21 '05 #15
I never use Option Strict Off, even dealing with COM Interop, I use
Reflection if I need to use late bound calls, even if it takes more code.
Maybe I would choose Option Strict Off if I could apply that option only to
a region of code rather than to the whole file...

--

Best regards,

Carlos J. Quintero

MZ-Tools: Productivity add-ins for Visual Studio .NET, VB6, VB5 and VBA
You can code, design and document much faster.
Free resources for add-in developers:
http://www.mztools.com

"Jay B. Harlow [MVP - Outlook]" <Ja************ @tsbradley.net> escribió en
el mensaje news:ep******** ******@TK2MSFTN GP15.phx.gbl...
Carlos,
I normally run with Option Strict On, however Option Strict Off is very
useful some times. For example when dealing with COM interop, especially
COM
objects written for VBScript where all return values were defined as
Variant...

I'm looking forward to Partial Classes in VB 2005 as they will allow me to
isolate just the parts of my class that needs Option Strict Off to its own
source file!

Jay


Nov 21 '05 #16
Carlos,
I don't use it for late bound calls, as much as eliminating the need for
downcasts.

Instead of Reflection, have you considered using CallByName?

When I use it (Option Strict Off) I limit it to as few as methods as
possible in as small a class as possible, which means I tend to have an
extra light class that is Option Strict Off. Also I will turn Option Strict
On to help eliminate any obvious errors, then turn Option Strict Off to run
the code. Then depending on the usage of the Option Strict Off class, I will
refactor it inline into the original class... Possibly eliminating the
Option Strict Off class.

As I stated I normally use Option Strict Off to encapsulate downcasts, which
I can easily add inline, however all the downcasts can make the code harder
to read. Hence the separate class to get "things working" then use the
Refactoring to improve the code.

| Maybe I would choose Option Strict Off if I could apply that option only
to
| a region of code rather than to the whole file...
As I suggested VB 2005's partial classes will simplify this (using Option
Strict Off), as I can put all the Option Strict Off stuff in one source
member & have it be a partial class of a larger class that is Option Strict
On. Eliminating the need for 2 classes...

http://msdn2.microsoft.com/library/y...us,vs.80).aspx

Something like:

' Something.Inter op.vb
Option Strict Off

Partial Class Something

Public Sub DoSomeLateBindi ng()
...
End Sub

Public Function EncapsulateDown cast() As SomethingSpecif ic
...
End Sub

End Class

' Something.vb
Option Strict On

Partial Class Something
' the majority of the class definition

Public Sub DoSomething()
DoSomeLateBindi ng()
Dim x As SomethingSpecif ic = EncapsulateDown cast()
End Sub

End Class

Notice how the Something class's definition is split between the
Something.Inter op.vb & Something.vb files. The Something.Inter op.vb contains
implicit downcasts & late bound code, while Something.vb contains early
bound code & explicit downcasts.

Hope this helps
Jay

"Carlos J. Quintero [VB MVP]" <ca*****@NOSPAM sogecable.com> wrote in message
news:eW******** ******@TK2MSFTN GP09.phx.gbl...
|I never use Option Strict Off, even dealing with COM Interop, I use
| Reflection if I need to use late bound calls, even if it takes more code.
| Maybe I would choose Option Strict Off if I could apply that option only
to
| a region of code rather than to the whole file...
|
| --
|
| Best regards,
|
| Carlos J. Quintero
|
| MZ-Tools: Productivity add-ins for Visual Studio .NET, VB6, VB5 and VBA
| You can code, design and document much faster.
| Free resources for add-in developers:
| http://www.mztools.com
|
| "Jay B. Harlow [MVP - Outlook]" <Ja************ @tsbradley.net> escribió en
| el mensaje news:ep******** ******@TK2MSFTN GP15.phx.gbl...
| > Carlos,
| > I normally run with Option Strict On, however Option Strict Off is very
| > useful some times. For example when dealing with COM interop, especially
| > COM
| > objects written for VBScript where all return values were defined as
| > Variant...
| >
| > I'm looking forward to Partial Classes in VB 2005 as they will allow me
to
| > isolate just the parts of my class that needs Option Strict Off to its
own
| > source file!
| >
| > Jay
| >
|
Nov 21 '05 #17
Hi Jay,
Instead of Reflection, have you considered using CallByName?
I'm not sure if I was aware of that function when I wrote the code some
years ago...today surely I would use CallByName.
As I suggested VB 2005's partial classes will simplify this (using Option
Strict Off), as I can put all the Option Strict Off stuff in one source
member & have it be a partial class of a larger class that is Option
Strict
On. Eliminating the need for 2 classes...


I still find unfortunate that Option Strict must be applied at file level (a
physical entity) and not at code level (a logical entity). Partial classes
allow you to have a single class (a great advance, certainly), but you are
still forced to have 2 files only for this purpose...

--

Best regards,

Carlos J. Quintero

MZ-Tools: Productivity add-ins for Visual Studio .NET, VB6, VB5 and VBA
You can code, design and document much faster.
Free resources for add-in developers:
http://www.mztools.com
Nov 21 '05 #18

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

Similar topics

1
379
by: noone | last post by:
I like to write my code with optionstrict set to on, except for the late binding errors I get when there is a reason to change some value in a control on a postback, like: Label4.Text = (sender.CommandArgument).tostring HiddenCreative.Value = sender.CommandArgument that are in a onclick handler for a webform. Looking at the doc it looks like the only option with OptionStrict is off or on. Is there a way to simply have the compleir...
1
1643
by: Karl Lang | last post by:
Hi I've created a new configuration section in Web.Config to hold the connection string for my database. If I have Option Strict On I get a message "Option Strict On disallows late binding" when I try to retrieve the string. Now I'd rather not turn off option strict but I'd also prefer to have my connection string in one place. Does anyone have any ideas where I'm going wrong with this? This is the code In Web.Config (I've removed some...
5
2060
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
2852
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.
4
8169
by: Heinz | last post by:
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...
6
1902
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
4
2816
by: Rippo | last post by:
Hi I have the following console application and am attempting to late bind a class with option strict on! However of course I cant and I get the following error "Option Strict On disallows late binding" at the line BL.a() in method Main How do I overcome this? Public Class test1
1
2379
by: Adotek | last post by:
Hi All, I've just converted a solution from .Net v1.1 to v2.0, by allowing Visual Studio 2005 to do the conversion. Since doing so, I am getting a compilation error as follows: "Option Strict On disallows late binding." This references line 1, which is my page directive:
2
8358
by: GS | last post by:
I have installed the ms PIA for ofc XP, and followed the article http://support.microsoft.com/kb/247412/ trying to paste into a worksheet However I got late binding not allowed errors .... webOCWraooer,Copy // get the desired data into clapboard
0
9826
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
10829
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10925
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
10468
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...
0
9640
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
8018
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...
1
4682
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
4276
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3282
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.