2013-04-10 155 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)。

您也可以尝试注释错误处理,然后运行它以查看错误是否有行号。