2013-04-10 190 views
0

**我是新來的VB和我收到和錯誤9,下標超出範圍。該錯誤表示它在下面的過程中。請讓我知道可能是什麼問題。我很欣賞你的幫助VB - 下標超出範圍,錯誤9

Private Sub RebuildGrid() 
    Const c_strProcedureName As String = "RebuildGrid" 
    Dim intIndex As Integer 

    On Error GoTo Error_Handler 

    For intIndex = 0 To g_intNumNucDataFields - 1 
     grdNuclides.Columns(intIndex).DataField = ga_strNucFieldName(intIndex) 
     grdNuclides.Columns(intIndex).Visible = False 

     If StrComp(ga_strNucFieldFormat(intIndex), "None", vbTextCompare) <> 0 Then 
      grdNuclides.Columns(intIndex).NumberFormat = ga_strNucFieldFormat(intIndex) 
     End If 

     grdNuclides.Columns(intIndex).Width = 1400 

     If StrComp(LCase$(ga_strNucFieldUnits(intIndex)), "none", vbTextCompare) = 0 Then 
      grdNuclides.Columns(intIndex).Caption = ga_strNucFieldTitle(intIndex) 
     Else 
      grdNuclides.Columns(intIndex).Caption = ga_strNucFieldTitle(intIndex) & _ 
      " " & vbCr & "(" & ga_strNucFieldUnits(intIndex) & ") " 
     End If 
     grdNuclides.Columns(intIndex).FooterText = "Reference" 
    Next intIndex 

    Exit Sub 
Error_Handler: 

    gud_PrgErr.Number = Err.Number 
    gud_PrgErr.Severity = 5 
    gud_PrgErr.Description = Err.Description 
    gud_PrgErr.Module = c_strModuleName 
    gud_PrgErr.Procedure = c_strProcedureName 
    Call Display_UI_Error 

End Sub 

Private Sub mnuFileExit_Click() 
    Unload Me 
End Sub 
+0

什麼行會拋出錯誤? 'ga_strNucFieldFormat'做什麼? – Brad 2013-04-10 20:18:39

+0

看來你的程序中有一些數組(如:'ga_strNucFieldFormat'),這個定義我們看不到。你的錯誤表明你試圖獲取這些數組中不存在的元素。當你開始循環時,試着檢查'LBound'和'Ubound',就像這樣:'For intIndex = LBound(ga_strNucFieldName)To Ubound(ga_strNucFieldName) – 2013-04-10 20:26:47

回答

0

確保g_intNumNucDataFields不大於列數較高(如grdNuclides.Columns.Count)。

您也可以嘗試註釋錯誤處理,然後運行它以查看錯誤是否有行號。

相關問題