vba VB - 下标超出范围,错误 9
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15935430/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
VB - Subscript out of range, error 9
提问by user2196817
**I am new to VB and I received and error 9, subscript out of range. The error indicated it was in the below procedure. Please let me know what might be the issue. I appreciate your assistance
**我是 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
回答by Jim Billig
Make sure g_intNumNucDataFields
is not higher than the number of columns (eg grdNuclides.Columns.Count
).
确保g_intNumNucDataFields
不高于列数(例如grdNuclides.Columns.Count
)。
You could also try commenting out the error handling and then running it to see if you get a line number on the error.
您还可以尝试注释掉错误处理,然后运行它以查看是否在错误上获得了行号。