Results 1 to 4 of 4
  1. #1
    5 Star Lounger
    Join Date
    Jan 2001
    Location
    Vancouver, Br. Columbia, Canada
    Posts
    632
    Thanks
    0
    Thanked 0 Times in 0 Posts

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

    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.
    --------------------------------------------------
    Jack MacDonald
    Vancouver, Canada

  2. #2
    Silver Lounger
    Join Date
    Jan 2001
    Location
    Indianapolis, Indiana, USA
    Posts
    1,862
    Thanks
    0
    Thanked 0 Times in 0 Posts

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

    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.

  3. #3
    5 Star Lounger
    Join Date
    Jan 2001
    Location
    Vancouver, Br. Columbia, Canada
    Posts
    632
    Thanks
    0
    Thanked 0 Times in 0 Posts

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

    Solved. Removed the "shared" parameter from the Function definition. (Not sure why it was present originally, or whether it will cause any subsequent problems.)
    --------------------------------------------------
    Jack MacDonald
    Vancouver, Canada

  4. #4
    5 Star Lounger
    Join Date
    Jan 2001
    Location
    Vancouver, Br. Columbia, Canada
    Posts
    632
    Thanks
    0
    Thanked 0 Times in 0 Posts

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

    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!
    --------------------------------------------------
    Jack MacDonald
    Vancouver, Canada

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •