VB.NET error

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • VB User

    #1

    VB.NET error

    While trying to code in VB.NET I get this error: Reference to a non-shared
    member requires an object reference.
    Any suggestions/ideas why this occurs?

    VBUser
  • Cor Ligthert [MVP]

    #2
    Re: VB.NET error

    VB User
    [color=blue]
    > While trying to code in VB.NET I get this error: Reference to a non-shared
    > member requires an object reference.
    > Any suggestions/ideas why this occurs?[/color]

    Mostly is it because an error in your code.

    Cor


    Comment

    • alantolan@users.com

      #3
      Re: VB.NET error

      Please post the code so that we can help, but from the message, it
      appears that you are referencing a non-shared function from within a
      shared one

      e.g.

      public class foo

      public Function Getbar() as string
      return "bar"
      end function

      public shared function GetMessage() as string
      return "foo" + Getbar()
      '<--- This line will cause the error
      end function

      end class

      Comment

      • VB User

        #4
        Re: VB.NET error

        With myTempImage
        .Aoi.SetBox(-1, 50, 50, 150, 150)
        Dim mcregionsT As New McRegions
        mcregionsT = IQL.McApplicati on.CreateOperat or("McRegions" ,
        myTempImage)
        mcregionsT.Thre shold.Execute()
        mcregionsT.Clea nUpBordersAndNo ise(.Aoi,
        mcRegionBorders .mcrbAllBorders , 25)
        .PointFeatures. CopyFrom(mcregi onsT.mpRgnCentr oidAsPoint.valu e)
        mcregionsT = Nothing
        .SaveAs("C:/temp/CentroidSoy.tif ")

        End With



        I get the error at the line: IQL.McApplicati on.CreateOperat or

        VBUser
        "alantolan@user s.com" wrote:
        [color=blue]
        > Please post the code so that we can help, but from the message, it
        > appears that you are referencing a non-shared function from within a
        > shared one
        >
        > e.g.
        >
        > public class foo
        >
        > public Function Getbar() as string
        > return "bar"
        > end function
        >
        > public shared function GetMessage() as string
        > return "foo" + Getbar()
        > '<--- This line will cause the error
        > end function
        >
        > end class
        >
        >[/color]

        Comment

        • Chris

          #5
          Re: VB.NET error

          VB User wrote:[color=blue]
          > With myTempImage
          > .Aoi.SetBox(-1, 50, 50, 150, 150)
          > Dim mcregionsT As New McRegions
          > mcregionsT = IQL.McApplicati on.CreateOperat or("McRegions" ,
          > myTempImage)
          > mcregionsT.Thre shold.Execute()
          > mcregionsT.Clea nUpBordersAndNo ise(.Aoi,
          > mcRegionBorders .mcrbAllBorders , 25)
          > .PointFeatures. CopyFrom(mcregi onsT.mpRgnCentr oidAsPoint.valu e)
          > mcregionsT = Nothing
          > .SaveAs("C:/temp/CentroidSoy.tif ")
          >
          > End With
          >
          >
          >
          > I get the error at the line: IQL.McApplicati on.CreateOperat or
          >
          > VBUser
          > "alantolan@user s.com" wrote:
          >
          >[color=green]
          >>Please post the code so that we can help, but from the message, it
          >>appears that you are referencing a non-shared function from within a
          >>shared one
          >>
          >>e.g.
          >>
          >>public class foo
          >>
          >> public Function Getbar() as string
          >> return "bar"
          >> end function
          >>
          >> public shared function GetMessage() as string
          >> return "foo" + Getbar()
          >>'<--- This line will cause the error
          >> end function
          >>
          >>end class
          >>
          >>[/color][/color]

          mcregionsT = IQL.McApplicati on.CreateOperat or("McRegions" , myTempImage)

          Where do you define an instance of IQL? Since you are trying to do an
          operation against a member of IQL (McApplication in this case) somewhere
          you have to create an instance of IQL (most likely using new statement)
          What you have would be fine if CreateOperator was marked as "shared"
          which is is not, hence the error message.


          Dim mcregionsT As New McRegions
          This is an error. What you are doing is creating a new instance of
          McRegions. Then the very next statement you lose that instance and
          point to another new instance that is returned by IQL.McApplictio n.....

          Instead do:
          Dim mcregionsT as McRegions
          This makes a pointer that will point to an McRegions object but doesn't
          just yet. Your next line then have mcregionsT point to the object.


          Chris

          Comment

          Working...