問題がどこにあるのでしょうか?コードはfrmFacilityから実行され、ユーザーコントロールにシフトします:ラインIf facilityForm.IsOnPrimaryView Then
でプロパティを使用しているときにNull Refrence例外が発生する
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
、私はNullReferenceException
を取得します。理由を知っていますか?
私はそのシングルトンで作業する必要があるので、私はfrmFacility
の新しいインスタンスを追加するとき、それはでtrue
に設定する必要がありながら、IsOnPrimaryMode
がfalse
に設定されているが、また、私は、facilityForm
の新しいインスタンスを作成することはできません。 gotoday
subからfrmFacility
。
OK、ありがとうannaですが、実際には間違っている必要がありますが、新しいインスタンスを作成するときにtrueに設定されていませんか? – amir
@amir恐らく 'frmFacility'の既存のインスタンスをそのメソッドに渡すか、それを同じクラスのプロパティを通して公開する必要があります。 –