Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 2004

    Question Unanswered: Subscript out of range Run time error 9

    I am trying to click on one button on the screen i am getting this Error, actually there are 16 buttons on the screen. Other buttons works fine as there are 16 buttons on the screen

    Public Sub cmdLvl2Click(ByVal aIndex As Integer, ByVal aiButton As Integer)

    'If the time Interval of the tmrCreateProcess
    'timer is set that means the task is in the que and that the finction is
    'called successively.
    If frmmain.tmrCreateProcess.Interval Then Exit Sub
    If aiButton = 2 And objNav.OperationMode = gctEditor Then

    'If aIndex < objNav.TaskButtons.Count Then
    objNav.CurrentButtonId = objNav.TaskButtons.Item(aIndex + 1).ButtonID
    Set cobjFrmTaskOp = New cTaskOpDisplay
    cobjFrmTaskOp.Parent = Parent
    If Not (cobjFrmTaskOp Is Nothing) Then
    Set cobjFrmTaskOp = Nothing
    End If
    Call RefreshButtons
    'End If
    If aiButton = 1 And objNav.OperationMode = gctNavigator And _
    objNav.TaskButtons.Item(aIndex).TaskId <> 0 Then
    'Ref-13518 :set the global g_objmaindisplay object,
    'The object is used by the tmrCreateProcess control to execute the clicked
    Set g_objmaindisplay = Me
    g_index = aIndex
    frmmain.tmrCreateProcess.Interval = 100
    'ExecuteBtnTask (aIndex)
    ' Ref-13518 the above code commented ,since the same is being
    'done by the tmrCreateProcess control
    End If
    End If
    Screen.MousePointer = vbNormal
    End Sub

    I am getting the Error over here
    If aiButton = 1 And objNav.OperationMode = gctNavigator And _
    objNav.TaskButtons.Item(aIndex).TaskId <> 0 Then
    Appreciate your help

  2. #2
    Join Date
    Jul 2004
    So Cal
    Set a breakpoint at the start of thet subroutine and single-step through the code.
    Verify the values of "aIndex" and "aiButton".

  3. #3
    Join Date
    Oct 2003
    Also watch-out for those commented-out IF statements.

    This is the kind of cryptic code that well deserves the five minutes of work that it would take to clean it up and to document what is actually supposed to be happening. It also contains some useless bogosities like "if x is not nothing then set it to nothing." (i.e. what difference does it make what the initial-value is in either case?)

    One must assume that the value of aIndex is bogus because there are no other array-indices in the statement. But no one thought to add code to check the value, did they? Maybe someone was trying to save the computer a few microseconds, although at the expense of costing your employer hundreds or thousands of dollars to pay people like you to find bugs like that in code like that.

    Far better to have the computer check for error-conditions that would crash the code, and to produce meaningful messages.
    Quote Originally Posted by The Elements of Programming Style (Kernighan and Plauger):
    Put diagnostics into your code as you write it. When the code is completely debugged, and only then ... keep them in.
    ChimneySweep(R): fast, automatic
    table repair at a click of the

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts