error when Option Strict On

S

Starbuck

Hi

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

Private Sub optWithTone_CheckedChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles optWithTone.CheckedChanged

If eventSender.Checked Then

pAlarmOption = NokiaCLCalendar.CalendarAlarmType.CALENDAR_ALARM_WITH_TONE

txtAlarmTime.Enabled = True

End If

End Sub



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

Thanks in advance
 
H

Herfried K. Wagner [MVP]

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

Private Sub optWithTone_CheckedChanged(ByVal eventSender As System.Object,
ByVal >eventArgs As System.EventArgs) Handles optWithTone.CheckedChanged

If eventSender.Checked Then

\\\
If DirectCast(eventSender, RadioButton).Checked Then
...
End If
///
 
A

Adam Goossens

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
"RadioButton" first:

----
If DirectCast(eventSender, RadioButton).Checked 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.
 
S

Starbuck

Thanks Guys



Adam Goossens said:
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 "RadioButton" first:

----
If DirectCast(eventSender, RadioButton).Checked 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.
 

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