VB.NET error

G

Guest

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
 
C

Cor Ligthert [MVP]

VB User
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?

Mostly is it because an error in your code.

Cor
 
A

alantolan

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
 
G

Guest

With myTempImage
.Aoi.SetBox(-1, 50, 50, 150, 150)
Dim mcregionsT As New McRegions
mcregionsT = IQL.McApplication.CreateOperator("McRegions",
myTempImage)
mcregionsT.Threshold.Execute()
mcregionsT.CleanUpBordersAndNoise(.Aoi,
mcRegionBorders.mcrbAllBorders, 25)
.PointFeatures.CopyFrom(mcregionsT.mpRgnCentroidAsPoint.value)
mcregionsT = Nothing
.SaveAs("C:/temp/CentroidSoy.tif")

End With



I get the error at the line: IQL.McApplication.CreateOperator

VBUser
 
C

Chris

VB said:
With myTempImage
.Aoi.SetBox(-1, 50, 50, 150, 150)
Dim mcregionsT As New McRegions
mcregionsT = IQL.McApplication.CreateOperator("McRegions",
myTempImage)
mcregionsT.Threshold.Execute()
mcregionsT.CleanUpBordersAndNoise(.Aoi,
mcRegionBorders.mcrbAllBorders, 25)
.PointFeatures.CopyFrom(mcregionsT.mpRgnCentroidAsPoint.value)
mcregionsT = Nothing
.SaveAs("C:/temp/CentroidSoy.tif")

End With



I get the error at the line: IQL.McApplication.CreateOperator

VBUser
:

mcregionsT = IQL.McApplication.CreateOperator("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.McAppliction.....

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top