2014-11-04 49 views
2

當我試圖調用此構造函數時出現錯誤Constructor call is valid only as the first statement in an instance constructor。我該如何糾正?「構造函數調用僅作爲第一條語句有效」錯誤,但它是第一條語句

我調用構造函數是這樣的:

  Dim frmPull As Shipping.frmPullFromLocation 
      frmPull = Shipping.frmPullFromLocation.New(datPickListDate, datRequestDate, datShipDate, intList, intQuantity, intRequest, strAdditionalInfo, strJobNumber, strItemCode) 
      frmPull.ShowDialog() 

Public Sub New(ByVal datPickListDate As Date, ByVal datRequestDate As Date, ByVal datShipDate As Date, ByVal intList As Integer, ByVal intQuantity As Integer, ByVal intRequest As Integer, ByVal strAdditionalInfo As String, ByVal strJobNumber As String, ByVal strItemCode As String) 
     MyBase.New() 

     'Set local variables to the parameters passed in. 
     Me.datPickListDate = datPickListDate 
     Me.datRequestDate = datRequestDate 
     Me.datShipDate = datShipDate 
     Me.intList = intList 
     Me.intQuantity = intQuantity 
     Me.intRequest = intRequest 
     Me.strAdditionalInfo = strAdditionalInfo 
     Me.strJobNumber = strJobNumber 
     Me.strItemCode = strItemCode 

     Dim _frmPullFromLocation As frmPullFromLocation = Me 
     AddHandler MyBase.Load, New EventHandler(AddressOf _frmPullFromLocation.frmPullFromLocation_Load) 
     Me.blnShowMessage = True 
     Me.InitializeComponent() 
    End Sub 
+3

接下來的問題將會是你刪除/忽略了''在InitializeComponent()調用後添加任何初始化.'設計器生成的註釋 – Plutonix 2014-11-04 17:58:16

+0

@Plutonix - 看到構建和運行正常...你能詳細說明嗎? – MAW74656 2014-11-04 18:02:38

+0

@Pututix - 它們是vars,但是你建議在Me.InitializeComponent()調用之後進行初始化嗎? – MAW74656 2014-11-04 18:10:20

回答

2
 Dim frmPull As Shipping.frmPullFromLocation 
     frmPull = Shipping.frmPullFromLocation.New(datPickListDate, datRequestDate, datShipDate, intList, intQuantity, intRequest, strAdditionalInfo, strJobNumber, strItemCode) 
     frmPull.ShowDialog() 

改變,要

 Dim frmPull As Shipping.frmPullFromLocation 
     frmPull = new Shipping.frmPullFromLocation(datPickListDate, datRequestDate, datShipDate, intList, intQuantity, intRequest, strAdditionalInfo, strJobNumber, strItemCode) 
     '   ^^^ new! 
     frmPull.ShowDialog() 

你不叫新像一個共享或靜態方法。

+0

哦。我當然知道,但現在忘了。多麼尷尬...... – MAW74656 2014-11-04 17:59:14

+1

不尷尬;) – hometoast 2014-11-04 18:00:20

相關問題