Hi Guys,
Another error and I'm not sure where it is comming from:
Code:Structure structHours Dim StdHours As Integer Dim OvHours As Integer Dim TotHours As Integer End Structure Dim arHours(i) As structHours Private Sub CalculateHoursSub() 'Defining Local Subroutine variables Dim intOverTimeHours As Integer 'Holds overtime hours during this subroutine Dim intStandardHours As Integer 'Holds standard hours during this subroutine 'This subroutine takes the entered number of hours, calculates the no of standard and over time 'hours, puts them into arrays, and updates variables for the totals of these hours for use in 'the frmEmployeePayeDetails and frmCalculatedMonthlyPaye. 'Adds 1 to the NoOfDaysCounter, makes the UndoLastEntry button visiable after the 'first value has been entered and reads the hours entered from the text box into variable. intNoOfDaysCounter = intNoOfDaysCounter + 1 Me.UndoButton.Enabled = True intEnteredHours = CInt(Me.NoOfHoursTextBox.Text) 'This if statement sets the variables for the amount standard and over time hours If intEnteredHours > 8 Then intStandardHours = 8 intOverTimeHours = (intEnteredHours - intStandardHours) Else intStandardHours = intEnteredHours intOverTimeHours = 0 End If 'Adds the values above to the listview Dim LVItems As New ListViewItem LVItems.Text = CStr(intStandardHours) LVItems.SubItems.Add(CStr(intOverTimeHours)) LVItems.SubItems.Add(CStr(intEnteredHours)) Me.EnteredHoursListView.Items.Add(LVItems) 'Puts the hours variables into an array arHours(nIndexItems).StdHours = intStandardHours arHours(nIndexItems).OvHours = intOverTimeHours arHours(nIndexItems).TotHours = intEnteredHours 'Adds standard and overtime variables for this entry to the running total of hours intTotalHours = intTotalHours + intEnteredHours intTotalStandardHours = intTotalStandardHours + intStandardHours intTotalOvertTimeHours = intTotalOvertTimeHours + intOverTimeHours 'Resets hours entry box Me.NoOfHoursTextBox.Clear() Me.NoOfHoursTextBox.Text = "0" If intNoOfDaysCounter <> intNoOfDays + 1 Then 'Adds one to the nhours variable used to track the current line of the array nIndexItems = nIndexItems + 1 intUndo = nIndexItems 'Updates the day text box and sets focus on EnteredHoursTextBox Me.DayLabel.Text = CStr(intNoOfDaysCounter) Me.NoOfHoursTextBox.Focus() Else MsgBox("You have enter the required number of days. Please close the form to continue") Me.NoOfHoursTextBox.Enabled = False Me.AcceptButton.Enabled = False End If End Sub
When I push the button the first time this works fine. When I do it a second time I get the error:
Index is ouside the bounds of the array
Hovering over where the code breaks down:
shows that the index value is currently 1. Howevering over i in :Code:arHours(nIndexItems).StdHours = intStandardHours
Shows i to have a value of 30. Where is this errors comming from?Code:Dim arHours(i) As structHours




Reply With Quote