Reputation: 1215
This question is with VB2008 Express.
I'm making a usercontrol which uses a structured property. Both the control and the overall project have an identical structure. The problem is that within the main project, attempts to assign a place to this property results in: "Reference to a non-shared member requires an object reference."
I have no clue what that means, nor how to deal with it. Microsoft's help babbles something like: "You are referencing a non shared member, so an object reference will be required."
Well gee Microsoft, I read the error description so no shiznit... But what's that mean? (I came from VB6 and I'm self-taught by example from there so please go easy on me.)
Of course I could assign each individual piece of the structure as its own property, such as "Street" "City", etc. but there are reasons I prefer to do it in one step, as it is validated all at once by the usercontrol upon assignment.
Any help getting my usercontrol and my main project to pass a "place" to each other?
Public Structure Place
Public PlaceName As String
Public Street As String
Public Apt As String
Public City As String
Public State As String
Public Zip As String
Public VerifiedStatus As Integer
Public Lat As Single
Public Lng As Single
End Structure
Public Property CurrentPlace() As Place
Get
Dim ThisPlace As New Place
ThisPlace.Street = Trim(Me.txtStreet.Text)
ThisPlace.Apt = Trim(txtAptNo.Text)
ThisPlace.City = Trim(txtCity.Text)
ThisPlace.State = Trim(lblState.Text)
ThisPlace.Zip = Trim(txtZip.Text)
ThisPlace.Lat = MyLat
ThisPlace.Lng = MyLng
ThisPlace.PlaceName = ""
'This control doesn't take placenames but they exist in the structure.
ThisPlace.VerifiedStatus = MyVerifiedStatus
Return ThisPlace
End Get
Set(ByVal value As Place)
AsLoadedApt = Trim(value.Apt)
AsLoadedCity = Trim(value.City)
AsLoadedLat = value.Lat
AsLoadedLng = value.Lng
AsLoadedState = Trim(value.State)
AsLoadedStreet = Trim(value.Street)
AsLoadedVerifiedStatus = value.VerifiedStatus
AsLoadedZip = Trim(value.Zip)
txtStreet.Text = AsLoadedStreet
txtAptNo.Text = AsLoadedApt
txtCity.Text = AsLoadedCity
lblState.Text = AsLoadedState
txtZip.Text = AsLoadedState
MyVerifiedStatus = AsLoadedVerifiedStatus
MyLat = AsLoadedLat
MyLng = AsLoadedLng
Call ShowStatus()
End Set
End Property
Upvotes: 0
Views: 508
Reputation: 6948
With your structure inside the control and the usercontrol file as part of the project, the structure will be exposed as a type by qualifying it as part of the usercontrol:
Dim NewPlace As New UserControl1.Place
Now since you're using the same structure, the NewPlace object can be used to set the CurrentPlace property
With NewPlace
.Apt = "Apt"
.City = "City"
.Lat = 0
.Lng = 0
.State = "State"
.Street = "Street"
.Zip = "Zip"
End With
UserControl11.CurrentPlace = NewPlace
If it's part of a different project in the same solution add the qualification for the project as well.
Upvotes: 2