2012-04-24 58 views
2

我想一個表單對象存儲到一個變量,但沒有成功:形式是沒有定義VB.NET

此代碼不起作用:

Dim invoice_form As billing_new_invoice 

    'Get last remote Row 
    Dim last_row As Integer = CType(main.ActiveMdiChild, invoice_form).invoiceitems_new_invoice.Rows.Count - 1 

    Dim count_row As Integer = CType(main.ActiveMdiChild, invoice_form).invoiceitems_new_invoice.Rows.Count() 

此代碼的工作:

Dim invoice_form As billing_new_invoice 

    'Get last remote Row 
    Dim last_row As Integer = CType(main.ActiveMdiChild, billing_new_invoice).invoiceitems_new_invoice.Rows.Count - 1 

    Dim count_row As Integer = CType(main.ActiveMdiChild, billing_new_invoice).invoiceitems_new_invoice.Rows.Count() 

Error

我需要的形式實例存儲在變量(invoice_form),即庫侖d用於多行代碼中,但它表示(類型'invoice_form'未定義。) 任何人有想法解決這個問題嗎?

回答

2

不是很清楚問題是什麼。我認爲你正在尋找的東西是這樣的:

If TypeOf Me.ActiveMdiChild Is billing_new_invoice Then 
    Dim invoice_Form As billing_new_invoice = Me.ActiveMdiChild 

    Dim last_row As Integer = invoice_form.invoiceitems_new_invoice.Rows.Count - 1 
    Dim count_row As Integer = invoice_form.invoiceitems_new_invoice.Rows.Count() 

    //'etc 

End If 

與不工作的代碼的問題是,它試圖將它轉換成一個變量,而不是一個類型。 invoice_form是一個變量,billing_new_invoice是一個類型。

2

CType用於類型轉換,而不是變量賦值。你想要做的是先將變量賦值給窗體,然後使用該變量:

Dim invoice_form As billing_new_invoice = CType(main.ActiveMdiChild, billing_new_invoice) 
Dim last_row As Integer = invoice_form.invoiceitems_new_invoice.Rows.Count - 1