473,791 Members | 2,807 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

error when Option Strict On

Hi

The following generates an error when Option Strict is On
Can anytell tell me how to get round this please.

Private Sub optWithTone_Che ckedChanged(ByV al eventSender As System.Object, ByVal eventArgs As System.EventArg s) Handles optWithTone.Che ckedChanged

If eventSender.Che cked Then

pAlarmOption = NokiaCLCalendar .CalendarAlarmT ype.CALENDAR_AL ARM_WITH_TONE

txtAlarmTime.En abled = True

End If

End Sub

The control is a radio button and the error is - Option Strict On disallows late binding.

Thanks in advance


Nov 21 '05 #1
3 2006
"Starbuck" <St******@tisco ni.com> schrieb;
'The following generates an error when Option Strict is On
Can anytell tell me how to get round this please.

Private Sub optWithTone_Che ckedChanged(ByV al eventSender As System.Object,
ByVal >eventArgs As System.EventArg s) Handles optWithTone.Che ckedChanged

If eventSender.Che cked Then
\\\
If DirectCast(even tSender, RadioButton).Ch ecked Then
...
End If
///
The control is a radio button and the error is - Option Strict On
disallows late binding.


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

Nov 21 '05 #2
Hi Starbuck,

"Late Binding" is the practice of dynamically discovering the type of an
object at runtime. It incurs a performance penalty since .NET has to do
a lot of running around for one simple statement.

Late binding also makes for less readable code, which is one of the
reasons coding with "Option Strict On" is recommended.

So before you could check the "Checked" (haha) property of the
eventSender argument, you need to cast eventSender to the type
"RadioButto n" first:

----
If DirectCast(even tSender, RadioButton).Ch ecked Then
' do the rest here...
End If
----

The inverse of late-binding is early binding. In early-binding the types
of objects are known at compile time and the compiler handles them
accordingly.

The cast above makes the code early-bound (the compiler knows the real
type of eventSender at compile-time) and helps create more readable code.

Regards,
-Adam.

Starbuck wrote:
Hi

The following generates an error when Option Strict is On
Can anytell tell me how to get round this please.
Private Sub optWithTone_Che ckedChanged(ByV al eventSender As
System.Object, ByVal eventArgs As System.EventArg s) Handles
optWithTone.Che ckedChanged

If eventSender.Che cked Then

pAlarmOption =
NokiaCLCalendar .CalendarAlarmT ype.CALENDAR_AL ARM_WITH_TONE

txtAlarmTime.En abled = True

End If

End Sub

The control is a radio button and the error is - Option Strict On
disallows late binding.

Thanks in advance



Nov 21 '05 #3
Thanks Guys

"Adam Goossens" <ad**********@u sers.sourceforg e.net> wrote in message
news:eN******** ******@TK2MSFTN GP15.phx.gbl...
Hi Starbuck,

"Late Binding" is the practice of dynamically discovering the type of an
object at runtime. It incurs a performance penalty since .NET has to do a
lot of running around for one simple statement.

Late binding also makes for less readable code, which is one of the
reasons coding with "Option Strict On" is recommended.

So before you could check the "Checked" (haha) property of the eventSender
argument, you need to cast eventSender to the type "RadioButto n" first:

----
If DirectCast(even tSender, RadioButton).Ch ecked Then
' do the rest here...
End If
----

The inverse of late-binding is early binding. In early-binding the types
of objects are known at compile time and the compiler handles them
accordingly.

The cast above makes the code early-bound (the compiler knows the real
type of eventSender at compile-time) and helps create more readable code.

Regards,
-Adam.

Starbuck wrote:
Hi
The following generates an error when Option Strict is On
Can anytell tell me how to get round this please.
Private Sub optWithTone_Che ckedChanged(ByV al eventSender As
System.Object, ByVal eventArgs As System.EventArg s) Handles
optWithTone.Che ckedChanged

If eventSender.Che cked Then

pAlarmOption =
NokiaCLCalendar .CalendarAlarmT ype.CALENDAR_AL ARM_WITH_TONE

txtAlarmTime.En abled = True

End If

End Sub

The control is a radio button and the error is - Option Strict On
disallows late binding.

Thanks in advance

Nov 21 '05 #4

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

Similar topics

8
2324
by: eje | last post by:
IsNumeric(value) should return false if value "can not be successfully converted to a Double." Instead I get the following error message: "Input string was not in a correct format." I use the following function in a validating class to use when needed. (Value = H880118A gave the error (like other 'unconvertible' strings)) Public Function Numeric(ByVal value) As Boolean
5
5040
by: ddd | last post by:
Hi, I am having problems with using the DrawToDC of the MSHTML.iHTMLElementRender in a VB.net application. For some reason I am getting a "catastrophic error". I am basing the code on c# examples, and I am not sure what exactly I am doing wrong. From the C# posts it seems that the drawtodc has a bug and you need to redifine it, so i followed their advice and specified an interface as below:
4
13779
by: dc15 | last post by:
For an intro to VB project I have to write a program which takes an amount of Miles, Yards, and Inches.....and converts it to metric (KM, M, and CM) when all values are entered to the input text boxes it works fine, but if there is a number missing I get the following error: An unhandled exception of type 'System.InvalidCastException' occurred in microsoft.visualbasic.dll Additional information: Cast from string "" to type 'Double' is...
2
1292
by: philip | last post by:
Private Sub FlowLayoutPanel1_DragDrop(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles FlowLayoutPanel1.DragDrop If e.Data.GetDataPresent(DataFormats.FileDrop) Then Dim fullFilenames() As String fullFilenames = e.Data.GetData(DataFormats.FileDrop) End If End Sub Line 'fullFilenames = e.Data.GetData(DataFormats.FileDrop)' give the Error
7
1883
by: Charlie Brookhart | last post by:
I have a program (posted below) that is supposed to take liters, which is the user input, and convert it to pints and gallons. The pints and gallons are displayed in a read only textbox. I don't understand how to fix the problem. 'declaring variables Dim totalLiters As Double = Convert.ToDouble(txtLiters.Text) Dim totalPints As Double = Convert.ToDouble(txtPints.Text)
2
1329
by: Justin | last post by:
I have set Option Strict On I also have Enum AssemblyLineStatus As Integer My question is how come there is no compilation error when I compile following code? If CInt(ddlStatus.SelectedItem.Value) = AssemblyLineStatus.Client Then ' do whatever End If Shouldn't this cause a compilation error? I know in C#, you have to
4
3785
by: Neo | last post by:
I found on error resume next doesn't work in for each... e.g. on error resume next for each x in y 'do stuff next if you have an error in for each loop, it falls in infinite loop... it doesn't move to next element... this sad thing but, it's indication that we must move to try catch instead of on error.
4
1640
by: =?Utf-8?B?UGl0Rw==?= | last post by:
Here the facts as code sample: Public Class Class1 Sub ABC(ByVal item As IUnit) End Sub End Class Public Interface IUnit ' or any other Interface ReadOnly Property Heureka() As Activator ReadOnly Property Reference() As String
2
1847
by: Francine | last post by:
Below is the code - I did not write this. This is a legacy program written in Perl, Html and java. I'm supposed to convert to dot net. This is the original code I was given. When I click on the create button after entering a new Workplan name, I get the jScript error: <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html...
0
10426
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...
0
9993
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
9029
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
7537
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
6776
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5430
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...
0
5558
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4109
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
3
2913
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.