这个问题与VB2008 Express有关。
我正在制作一个使用结构化属性的usercontrol。控制和整个项目都具有相同的结构。问题是在主项目中,尝试为此属性分配位置会导致:“对非共享成员的引用需要对象引用。”
我不知道这意味着什么,也不知道如何处理它。微软的帮助唠叨如下:“你正在引用一个非共享成员,因此需要一个对象引用。”
嗯,微软,我读错误描述所以没有shiznit ......但这是什么意思? (我来自VB6,我从那里通过实例自学,所以请放轻松我。)
当然,我可以将结构的每个单独部分分配为自己的属性,例如“街道”“城市”等,但有理由我喜欢一步完成,因为它一次性验证由用户控制分配。
有什么帮助让我的用户控件和我的主项目相互传递一个“位置”?
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
答案 0 :(得分:2)
将控件中的结构和usercontrol文件作为项目的一部分,通过将结构限定为usercontrol的一部分,结构将作为类型公开:
Dim NewPlace As New UserControl1.Place
现在,由于您使用相同的结构,NewPlace对象可用于设置CurrentPlace属性
With NewPlace
.Apt = "Apt"
.City = "City"
.Lat = 0
.Lng = 0
.State = "State"
.Street = "Street"
.Zip = "Zip"
End With
UserControl11.CurrentPlace = NewPlace
如果它是同一解决方案中不同项目的一部分,也可以为项目添加资格。