-1

我有一个多维数组,它将保存 3 位值,并且值将通过从 db 读取通过循环添加。当它出现这行代码时:

*MenuAccess(.Fields("GROUPNO").Value, .Fields("ITEMNO").Value, .Fields("SUBITEMNO").Value) = OKNO*

它遇到错误,“对象引用未设置为对象的实例。”

Public MenuAccess(100, 30, 50) As Boolean

Private Sub RtGetMenu_Access()
    Try
        Dim OKNO As Boolean

        Erase MenuAccess

        DBMgr = New cAdodb

        With DBMgr
            .openCnn(cnnSPR)
            .sql(rst1) = "Select * from BSMENU_ACCESS where LEVELCD = '" & Trim(UserTaskLevel) & "' Order by GROUPNO "
            .openRstRead(rst1)

            With .rst(rst1)
                Do While Not .EOF
                    If .Fields("GROUPNO").Value.ToString.Trim <> "" And .Fields("ITEMNO").Value.ToString.Trim <> "" And .Fields("SUBITEMNO").Value.ToString.Trim <> "" Then
                        If .Fields("LEVEL1").Value.ToString.Trim = "Y" Then OKNO = True Else OKNO = False

                        '=> ERROR: 'Object reference not set to an instance of an object.'
                        MenuAccess(.Fields("GROUPNO").Value, .Fields("ITEMNO").Value, .Fields("SUBITEMNO").Value) = OKNO

                    End If
                    .MoveNext()
                Loop
            End With

            .closeRst(rst1)
            .closeCnn(rst1)
        End With

        DBMgr = Nothing
    Catch ex As Exception
        If DBMgr.cnn(cnnSPR).State <> 0 Then
            DBMgr.closeCnn(cnnSPR)
            DBMgr = Nothing
        End If
    End Try

End Sub
4

1 回答 1

0

您缺少数组的初始化

Public MenuAccess(100, 30, 50) As Boolean   'Object not initialized in VB.NET

试试这个

Public MenuAccess() As New Boolean(100,30,50)

还将字段转换为整数Integer.TryPrase()

Dim i as Integer=-1, j as Integer=-1, k as Integer=-1
Integer.TryParse(.Fields("GROUPNO").Value.ToString(), i)
Integer.TryParse(.Fields("ITEMNO").Value.ToString(), j)
Integer.TryParse(.Fields("SUBITEMNO").Value.ToString(), k)

If i>=0 AndAlso j>=0 AndAlso k>=0 Then
    MenuAccess(i,j,k) = OkNo
End If
于 2012-06-22T13:20:57.770 回答