Shared Method Problem With "Global" Storage
- From: "eBob.com" <eBob.com@xxxxxxxxxxxxxxxx>
- Date: Fri, 19 Oct 2007 13:01:14 -0400
I have this nasty problem with Shared methods and what I think of as "global
storage" - i.e. storage declared outside of any subroutines or functions.
In the simple example below this "global" storage is ButtonHasBeenClicked.
In this simple example code in Form1 calls a routine in Module1 which then
calls code back in Form1 (subroutine WhatEver). WhatEver needs to access
ButtonHasBeenClicked but the reference to ButtonHasBeenClicked results in
the error reflected in the comment. I don't see any ambiguity in what I am
trying to do. I suspect there is some syntatic solution but I have been
unable to find it.
Thanks much for whatever solution and/or understanding you can provide.
Bob
Public Class Form1
Inherits System.Windows.Forms.Form
Dim ButtonHasBeenClicked As Boolean
#Region " Windows Form Designer generated code "
#End Region
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
ButtonHasBeenClicked = True
End Sub
Public Shared Sub WhatEver()
If ButtonHasBeenClicked Then ' Cannot refer to an instance member
of a class from within a shared method or shared member initializer without
an explicit instance of the class.
'do one thing
Else 'do something else
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
CalculateSomething()
If ButtonHasBeenClicked Then
'do something here; no problem referencing ButtonHasBeenClicked
here
End If
End Sub
End Class
Module Module1
Public Sub CalculateSomething()
Form1.WhatEver()
End Sub
End Module
.
- Follow-Ups:
- RE: Shared Method Problem With "Global" Storage
- From: Terry
- Re: Shared Method Problem With "Global" Storage
- From: Tom Shelton
- Re: Shared Method Problem With "Global" Storage
- From: Armin Zingler
- RE: Shared Method Problem With "Global" Storage
- Prev by Date: Re: Generic List Find.
- Next by Date: Re: Shared Method Problem With "Global" Storage
- Previous by thread: Unable tp play sound file in used in Code with Vista
- Next by thread: Re: Shared Method Problem With "Global" Storage
- Index(es):
Loading