2013-10-03 45 views
-4

我寫了這個代碼:的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.

這是怎麼回事?

回答

2

Dim f As ChatSystem創建對象參考f變量只是一個指針。你需要它指向一個實際的對象,它可以通過多種方式來完成:

Dim f As New ChatSystem 

f = New ChatSystem 

f = OtherChatSystemVariable 

然後上面將設置男,你的對象參考線的任何,到對象的實例。

+0

+1,即使在那裏TextBox1可能是沒有,你仍然會得到相同的錯誤。你也有A(1),其中A可能是Nothing。不知道TimeOfDay,但我也檢查確定。 :) – Neolisk

0

你必須與New關鍵字

Dim f As New ChatSystem 
f.TextBox1.Text &= "[ " & TimeOfDay & " ] Him: " & A(1) & vbNewLine & vbNewLine 
0

也許你應該在聲明f出現創建新實例初始化對象。

Dim f As new ChatSystem 
相關問題