'Me' is valid only within an instance method.

M

Materialised

Hi All,

I have a strange issue, and I am not sure if it is a error on my part, or a
visual studio bug.

I am using VS.Net 2003 Enterprise.

I have 2 event handlers as follows:

Public Shared Sub txtFace1_DoubleClick(ByVal sender As Object, ByVal e
As System.EventArgs) Handles txtFace1.DoubleClick
Dim SWin As New search
Caller = "Face1"
SWin.ShowDialog(Me)
End Sub

Private Sub txtFace2_DoubleClick(ByVal sender As Object, ByVal e As
System.EventArgs) Handles txtFace2.DoubleClick
Dim SWin As New search
Caller = "Face2"
SWin.ShowDialog(Me)
End Sub

However the first event handler gives me the following error:

C:\Documents and Settings\xxx\My Documents\Visual Studio Projects\Ware House
Control System\Forms\Form5.vb(884): 'Me' is valid only within an instance
method.

Yet the second event handler is fine and generates no warnings.

Does anyone know what this issue is?

Thanks
 
H

Herfried K. Wagner [MVP]

Materialised said:
Public Shared Sub txtFace1_DoubleClick(ByVal sender As Object, ByVal e
As System.EventArgs) Handles txtFace1.DoubleClick
[...]
C:\Documents and Settings\xxx\My Documents\Visual Studio Projects\Ware
House Control System\Forms\Form5.vb(884): 'Me' is valid only within an
instance method.

Remove the 'Shared' keyword.
 
C

Cor Ligthert [MVP]

Materialised.

No it is not a bug.

Is there any reason that you make that first event "Shared" and that second
not. I cannot think about any situation. However if it is a shared part of
your program, than it cannot be the referce to *this* class, shared is
usable from all classes.

I hope this helps,

Cor
 
M

Materialised

Materialised said:
Hi All,

I have a strange issue, and I am not sure if it is a error on my part, or
a visual studio bug.

I am using VS.Net 2003 Enterprise.

I have 2 event handlers as follows:

Public Shared Sub txtFace1_DoubleClick(ByVal sender As Object, ByVal e
As System.EventArgs) Handles txtFace1.DoubleClick
Dim SWin As New search
Caller = "Face1"
SWin.ShowDialog(Me)
End Sub

Private Sub txtFace2_DoubleClick(ByVal sender As Object, ByVal e As
System.EventArgs) Handles txtFace2.DoubleClick
Dim SWin As New search
Caller = "Face2"
SWin.ShowDialog(Me)
End Sub

However the first event handler gives me the following error:

C:\Documents and Settings\xxx\My Documents\Visual Studio Projects\Ware
House Control System\Forms\Form5.vb(884): 'Me' is valid only within an
instance method.

Yet the second event handler is fine and generates no warnings.

Does anyone know what this issue is?

Thanks

Thank you to those of you who replied.
 
B

Brad Rogers

Right, using the Shared keyword causes the thing to be created, you dont
need the "new" declaration to make an instance.

So it will complain if there is a mix of things created now, and things that
are not created until something creates them with 'new' at some later time,
there is no guarantee when those will exist. Kind of a logic error there.

If you declare something Shared, it is accessible by dot notation using the
Class name, right now. But the only solution appears in the use of
delegates.

Is this correct? Is there any easier way?
 

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