• Reference a textbox from a shared function (vb.net 2005)

    Home » Forums » Developers, developers, developers » DevOps Lounge » Reference a textbox from a shared function (vb.net 2005)

    Author
    Topic
    #446060

    Using VB.Net 2005 Express on Windows Vista. Modifying an open source program, so I am not the original author.

    On an existing form, I created a standard textbox named txtProgress. Tried to refer to the textbox in the form’s code module with the following statement:
    txtProgress.text = “fred”
    and was greeted with this error message:

    Error 2 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.

    The procedure where I am trying to add the line is defined with this line:

    Public Shared Function MergeShapefiles(ByVal InSFs() As String, ByVal OutSF As String, ByVal FilterDupsByGeometry As Boolean, ByVal FilterDupsByAttributes As Boolean, ByVal FilterDupsBySingleAttribute As String) As Boolean

    I am not familiar with the “Shared” parameter on the Function declaration, but it appears to affect the way that a textbox is allowed to be referenced. How do I reference a textbox on the form from within the Shared Function?

    Thanks.

    Viewing 1 reply thread
    Author
    Replies
    • #1083217

      Is there any particular reason you need the function to be shared? Try removing the Shared declaration from your function and that should fix the problem.

      For more details on the Shared keyword, check here.

      • #1083222

        Thanks, Mark. Your reply was not online when I first checked this morning. Did a bunch of online research, and came to the same conclusion that you did. Saw your message *after* posting my own. D’oh!

    • #1083221

      Solved. Removed the “shared” parameter from the Function definition. (Not sure why it was present originally, or whether it will cause any subsequent problems.)

    Viewing 1 reply thread
    Reply To: Reference a textbox from a shared function (vb.net 2005)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: