Shared Functions

SteveW

New Member
Is it possible to get a value from a form inside a shared function? I am having trouble getting a value from a form w/o it giving me the:<BR><BR> 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.<BR><BR>Any suggestions?<BR><BR>Matt<BR>hi,<BR><BR>use the variable as "shared" either private or public like below code<BR>if u use "private" use property to get the value<BR>if u use "public" variable u can access directly.<BR><BR>This is sample :-<BR>----------------<BR>Public Class Class1<BR> Private Shared x As Integer<BR> Public Shared Sub add(ByVal a As Integer, ByVal b As Integer)<BR> x = a + b<BR> End Sub<BR><BR> Public ReadOnly Property getValue()<BR> Get<BR> Return x<BR> End Get<BR><BR> End Property<BR>End Class<BR>-----------------------------<BR><BR>hope this may help u..<BR>regards<BR>yesuThat was a nice idea but the problem remains that I can't get my form value to a shared variable/function.<BR><BR>I am getting a:<BR> Reference to a non-shared member requires an object reference.<BR><BR>when I try to access stuff like loaddate.text.<BR><BR>MattHI, <BR><BR>i don't this what u need.<BR>in below code i am getting form value and passing to the shared function.<BR><BR>I just added the shared in textbox1<BR><BR><BR> Protected Shared WithEvents TextBox1 As System.Web.UI.WebControls.TextBox<BR><BR>Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click<BR> x()<BR> End Sub<BR> Public Shared Function x()<BR> Dim y As String<BR> y = TextBox1.Text<BR> Return y<BR> End Function<BR><BR>if this not your requirment, please explain the scenario,<BR>where u need that exactly?<BR>
 
Back
Top