Thanks perito. With using your code and some others my partner and I have gathered we came up with this:
Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
'adds ticked items to list boxes
Dim chkBakeItem As CheckBox
Dim intIndex As Integer = lbxOven1.Items.Count
Dim intIndex2 As Integer = lbxOven2.Items.Count
Dim intIndex3 As Integer = lbxoven3.Items.Count
If tbxStart.Text = "" Or tbxFinish.Text = "" Then
MessageBox.Show("Please enter Start and Finish times of shift before adding items")
Else : For Each chkBakeItem In gbxBakeryItems.Controls
If chkBakeItem.Checked = True And rdbOven1.Checked = True Then
lbxOven1.Items.Insert(intIndex - 3, (("00:00 ") + (chkBakeItem.Text)))
ElseIf chkBakeItem.Checked = True And rdbOven2.Checked = True Then
lbxOven2.Items.Insert(intIndex2 - 3, (("00:00 ") + (chkBakeItem.Text)))
ElseIf chkBakeItem.Checked = True And rdbOven3.Checked = True Then
lbxoven3.Items.Insert(intIndex3 - 3, (("00:00 ") + (chkBakeItem.Text)))
End If
Next
Dim intPosition, intBakeTime As Integer
Dim strCurrentString As String
Dim strBakeryItem As String
For i = 0 To lbxOven1.Items.Count
strCurrentString = lbxOven1.Items(i).ToString
strBakeryItem = strCurrentString.Substring(6, strCurrentString.Length - 6)
intPosition = strCurrentString.IndexOf("(")
intBakeTime = CInt(strCurrentString.Substring(intPosition + 1, 2))
'MessageBox.Show(intPosition & " " & intBakeTime)
If i = 0 Then
Else
'finds the space after the time in the string
Dim intspace As Integer = strCurrentString.IndexOf(" ")
'takes the string of the whole time
Dim strTime As String = strCurrentString.Substring(0, intspace)
'takes the string of the minutes
Dim strMinutes As String = strCurrentString.Substring(3, 2)
'finds position of ":"
Dim intColons As Integer = strCurrentString.IndexOf(":")
'takes string of the hrs
Dim strHours As String = strCurrentString.Substring(0, intColons - 1)
'take the previous time and add it to the beginning of the current item
Dim strPrevious As String = strMinutes(i - 1) ' This is where the error message comes up
'makes time of current item = previous time
Dim strNew As String = strPrevious
'edits string to add baking time
strMinutes = CStr(intBakeTime)
If CDbl(strMinutes) > 59 Then
strHours = CStr(CDbl(strHours) + 1)
strMinutes = CStr(60 - intBakeTime)
End If
The error message we get is "Index was outside the bounds of the array"
Any ideas on where we went wrong?