你看到问题所在吗?代码将从frmFacility运行,并将转换为UserControl:
Public Class frmFacility
Private primaryBaseDay As Date
Private isClassPrimaryView As Boolean = False
Friend WithEvents BookCtrl As ucBookCtrl2
Public Property Primary_BaseDay() As Date
Get
Return primaryBaseDay
End Get
Set(ByVal value As Date)
primaryBaseDay = value
End Set
End Property
Public Property IsOnPrimaryView() As Boolean
Get
Return isClassPrimaryView
End Get
Set(ByVal value As Boolean)
isClassPrimaryView = value
End Set
End Property
Public Sub GotoDay(ByVal theDay As Date)
Primary_BaseDay = theDay
IsOnPrimaryView = True
BookCtrl.GotoDay(theDay)
End Sub
End Class
Imports frmFacility
Public Class ucBookCtrl2
Public Sub GotoDay(ByVal whichDay As Date, Optional ByVal MainFacilityUsed As String = "")
Dim facilityForm As frmFacility
If facilityForm.IsOnPrimaryView Then
moDoBooking.m_BaseDay = facilityForm.Primary_BaseDay
moDoBooking.m_CurrentDay = whichDay
ShowDay()
RaiseEvent ChangeOfDay()
End Sub
End Class
在If facilityForm.IsOnPrimaryView Then
行,我得到NullReferenceException
。你知道原因吗?
此外,我无法创建facilityForm
的新实例,因为我需要使用其单例,但是当我添加frmFacility
的新实例时,IsOnPrimaryMode
已设置到false
,true
来自gotoday
的{{1}}。{/ 1}}。{/ 1}
答案 0 :(得分:3)
您没有将facilityForm
设置为任何内容,您只需声明frmFacility
类型的变量并将其命名为facilityForm
。当您尝试拨打facilityForm.IsOnPrimaryView
时,facilityForm
仍为null
。
答案 1 :(得分:1)
您实际上并没有使用facilityForm单例。你必须把它存放在某个地方。也许是Public Class
Shared test as New frmFacility
。
Form还没有IsOnPrimaryView属性,因为它没有实例化。实际上是Nothing
答案 2 :(得分:0)
您需要将IsOnPrimaryView属性设置为shared,否则您将获得NullReference异常。