如何访问这个变量?

How to access this variable?

我是 VB 的新手,我目前正在迁移一个我没有写入 .net 的 vb6 应用程序,我正在为这个错误而苦苦挣扎,

If TypeOf Application.OpenForms.Item(i) Is frmAddChangeDelete Then
            'UPGRADE_ISSUE: Control ctrlAddChangeDelete1 could not be resolved because it was within the generic namespace Form. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="084D22AD-ECB1-400F-B4C7-418ECEC5E36E"'

            If **Application.OpenForms.Item(i).ctrlAddChangeDelete1.ParentFormNumber = intFormNumber** Then

                If Application.OpenForms.Item(i).Text = "Add Proofed Expense Items" Then
                    boolAddProofed = True
                    Exit For

ctrlAddChangeDelete1 据说是从一个单独的 VB 文件调用朋友 class ctrlAddChangeDelete,所以我不确定为什么它说

"'ctrlAddChangeDelete1' is not a member of 'System.Windows.Forms.Form'."

感谢任何帮助,谢谢!

Application.OpenForms 是一个非强类型集合。
当您在那里引用元素时,您会得到一个通用表单。
在通用表单中,没有名为 ctrlAddChangeDelete1

的控件

如果您有一个派生的 class 名为 frmAddChangeDelete 的表单,并且此 class 有一个名为 ctrlAddChangeDelete1 的控件那么在尝试引用该控件之前,您需要将存储在 OpenForms 集合中的引用转换为您的特定表单 class。

此外,要从外部代码访问该控件,您还应该将修饰符 属性 设置为 Public 而不是默认的内部。否则,您将无法从 class.

外部的任何代码访问该控件

要正确检索您的表单,您可以编写

Dim delForm = Application.OpenForms.
                         OfType(Of frmAddChangeDelete)
                         FirstOrDefault()
If delForm Is Nothing Then
    ' No form of type frmAddChangeDelete is present in the collection
    ' write here your message and exit ?
Else 
    ' Now you can use delForm without searching again in the collection
    ......

上面的代码使用 IEnumerable.OfType 扩展,这需要 Imports System.Linq.
如果您不想使用它,那么您始终可以使用 TryCast 运算符来获取对正确 class

的引用
' Still you need a for loop up ^^^^ before these lines
Dim delForm = TryCast(Application.OpenForms(i), frmAddChangeDelete)
if delForm Is Nothing then 
   ....
else
   ....