error when Option Strict On

  • Thread starter Thread starter Starbuck
  • Start date Start date
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
 
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
///
 
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.
 
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.
 
Back
Top