Option Strict On -help

  • Thread starter carlin smith via .NET 247
  • Start date
C

carlin smith via .NET 247

I have an option strict on problem.

i am using the event for 1 button to be the event for several others, kind of like indexes in vb6.

it looks something like this:
*****
Private Sub btnNum0_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNum0.Click, btnNum1.Click

if sender.tag = "1" then blah blah blah
*****

with strict off it works fine
with strict on it says "option strict on disallows late binding" with the squigly line under sender.text.

this was microsofts solution to trying to do "indexes" or arrays with controls for vb.net. is there a way to get this to work or a better way to reference the controls or get around the control array thing?
 
M

Marina

Tag is an Object. You are comparing it to a string. That's why it doesn't
work.

Option Strict forces you to think about the types of your variables and
properties. If Tag was not assigned a string, this comparison would result
in an error. This way it is caught at run time.
 
H

Herfried K. Wagner [MVP]

carlin smith via .NET 247 said:
I have an option strict on problem.

i am using the event for 1 button to be the event for several others, kind
of like indexes in vb6.

it looks something like this:
*****
Private Sub btnNum0_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnNum0.Click, btnNum1.Click

if sender.tag = "1" then blah blah blah
*****

with strict off it works fine
with strict on it says "option strict on disallows late binding" with the
squigly line under sender.text.

\\\
Dim SourceControl As Control = DirectCast(sender, Control)
If SourceControl.Tag = "1" Then
...
End If
///
 
C

Cor Ligthert

Carlin
if sender.tag = "1" then blah blah blah
if Directcast(sender,Control).tag.ToString = "1" then blah blah blah

Or much nicer

Select Case DirectCast(sender,Control).Tag
Case "1"
bla bla bla
Case "2"

Else

End Select

I hope this helps?

Cor
 

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

Similar Threads


Top