0

**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

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
Brad
  • 11,934
  • 4
  • 45
  • 73
user2196817
  • 1
  • 1
  • 2
  • What line throws the error? What does `ga_strNucFieldFormat` do? – Brad Apr 10 '13 at 20:18
  • it seems you have some arrays in your procedure (like: `ga_strNucFieldFormat`) which definition we can't see. Your error suggest that you are trying to get element which doesn't exists within any of these arrays. When you start you loop try to check `LBound` and `Ubound`, something like that:`For intIndex = LBound(ga_strNucFieldName) To Ubound(ga_strNucFieldName)` – Kazimierz Jawor Apr 10 '13 at 20:26

1 Answers1

0

Make sure g_intNumNucDataFields is not higher than the number of columns (eg 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.

Jim Billig
  • 344
  • 2
  • 14