2012-11-23 82 views
0

我正在整理一個VB.net程序,下面的問題。基本上我有兩種形式。 Form1 and techs。表單1首先加載並且是我的「主」頁面。我想引用Form1上的技術變量。我公開宣稱這個變量像這樣:奇怪的運行時問題VB.net

Public jobID As String 

我然後在Form1上引用此像這樣:

昏暗工作的String = techs.jobID

這是我收到的錯誤:

An error occurred creating the form. See Exception.InnerException for details. The error is: An error occurred creating the form. See Exception.InnerException for details. The error is: The form referred to itself during construction from a default instance, which led to infinite recursion. Within the Form's constructor refer to the form using 'Me.' 

任何人都可以告訴我這裏出了什麼問題嗎?

+0

你可以顯示techs的構造函數嗎?即創建第二個表單實例的代碼位。 –

+0

事實上,考慮到這一點,我認爲問題在於技術人員引用的變量在引用之前尚未構建。 – user1352057

+0

技術人員必須首先實例化 –

回答

1

嘗試改變

Public jobID As String 

Public Shared jobID As String 
1

實例化第一科技股

Dim newtechs As New techs() 

然後,分配techs.jobID給字符串變量Form1中

Dim job As String = newtechs.jobID 
+0

Dim job As String = newtechs.jobID –

+0

抱歉,剛剛編輯:)謝謝Derek –