我寫了這個代碼:的Visual Basic Error對象
Dim f As ChatSystem
f.TextBox1.Text &= "[ " & TimeOfDay & " ] Him: " & A(1) & vbNewLine & vbNewLine
,它給了我這個錯誤:
Object reference not set to an instance of an object.
這是怎麼回事?
我寫了這個代碼:的Visual Basic Error對象
Dim f As ChatSystem
f.TextBox1.Text &= "[ " & TimeOfDay & " ] Him: " & A(1) & vbNewLine & vbNewLine
,它給了我這個錯誤:
Object reference not set to an instance of an object.
這是怎麼回事?
線Dim f As ChatSystem
創建對象參考。 f
變量只是一個指針。你需要它指向一個實際的對象,它可以通過多種方式來完成:
Dim f As New ChatSystem
f = New ChatSystem
f = OtherChatSystemVariable
然後上面將設置男,你的對象參考線的任何,到對象的實例。
你必須與New
關鍵字
Dim f As New ChatSystem
f.TextBox1.Text &= "[ " & TimeOfDay & " ] Him: " & A(1) & vbNewLine & vbNewLine
也許你應該在聲明f出現創建新實例初始化對象。
Dim f As new ChatSystem
+1,即使在那裏TextBox1可能是沒有,你仍然會得到相同的錯誤。你也有A(1),其中A可能是Nothing。不知道TimeOfDay,但我也檢查確定。 :) – Neolisk