changing text of a listbox item to match item above
I need this code to be able to take the time out of an item in a list box and replace the time of the item under. The code then needs to take the time in brackets at the end of the item and add it to the end of that time also.
e.g.
this program is meant to be used for a bakery to tell them what need to be baked and when
so the list box looks like
09:00 turn on oven (15)
09:15 cheese rolls (18)
09:33 knot rolls (15)
Etc
Etc
Feel free to write a new code if u want
Cause that one is confusing
Dim strCurrentString As String
Dim strLineTime As String
Dim intDuration As Integer
Dim intLastItem As Integer = lbxOven1.Items.Count - 1
Dim strHours As String
Dim strNewTimeMinutes As String
Dim strLastMinutes As String
Dim strLastHours As String
Dim strEndBit As String
Dim strNewString, strMinutes As String
'loop counts through all items in listbox
For I = 0 To lbxOven1.Items.Count - 1
If Not intLastItem = I Then
If I = 0 Then
'sets current string = to the curent item being worked on in loop
strCurrentString = lbxOven1.Items(I).ToString
'takes the time of the current item (I)
strLineTime = GetStartTime(strCurrentString)
'takes the text of current item (I)
strEndBit = strCurrentString.Substring(strCurrentString.IndexO f(" "))
'makes sure loop doesn't try to process last item
'takes the value of baking time between brackets
intDuration = GetDurationMinutes(strCurrentString)
'takes the minutes part of current time
strMinutes = GetMinutes(strLineTime)
' MessageBox.Show("strCurrenString=" & strCurrentString & " strMinutes=" & strMinutes & " strLineTime=" & strLineTime)
'takes hours part of current time
strHours = GetHours(strLineTime)
'stores value of time in minutes of current to be called on for next loop
strLastMinutes = strMinutes
' stores time in hrs of current item to be called on in next loop
strLastHours = strHours
'adds duration of baking onto minutes of current time
'sets current string = to the curent item being worked on in loop
Else : strCurrentString = lbxOven1.Items(I).ToString
'takes the time of the current item (I)
strLineTime = GetStartTime(strCurrentString)
'takes the text of current item (I)
strEndBit = strCurrentString.Substring(strCurrentString.IndexO f(" "))
'makes sure loop doesn't try to process last item
If Not intLastItem = I Then
'takes the value of baking time between brackets
intDuration = GetDurationMinutes(strCurrentString)
'takes the minutes part of current time
strMinutes = GetMinutes(strLineTime)
'MessageBox.Show("strCurrenString=" & strCurrentString & " strMinutes=" & strMinutes & " strLineTime=" & strLineTime)
'takes hours part of current time
strHours = GetHours(strLineTime)
'stores value of time in minutes of current to be called on for next loop
strLastMinutes = strMinutes
' stores time in hrs of current item to be called on in next loop
strLastHours = strHours
'adds duration of baking onto minutes of current time
strNewTimeMinutes = NewTimeMinutes(CStr(intDuration), strLastMinutes)
' MessageBox.Show(strNewTimeMinutes)
'adds previous hours with : and newMinutes and text
strNewString = strLastHours & ":" & strNewTimeMinutes & strEndBit
'removes old time
lbxOven1.Items.RemoveAt(I)
'inserts new time
lbxOven1.Items.Insert(I, strNewString)
End If
End If
End If
Private Function GetStartTime(ByVal strLine As String) As String
Dim strResult As String = ""
Dim intSpace As Integer = strLine.IndexOf("
Dim intSpace As Integer = strLine.IndexOf(")
strResult = strLine.Substring(0, intSpace)
Return strResult
End Function
Private Function GetDurationMinutes(ByVal strLine As String) As Integer
Dim strResult As String = "")
strResult = strLine.Substring(0, intSpace)
Return strResult
End Function
Private Function GetDurationMinutes(ByVal strLine As String) As Integer
Dim strResult As String = "("
Dim intFirstBracket As Integer = strLine.IndexOf(")")
Dim intLastBracket As Integer = strLine.IndexOf(""
Dim intColons As Integer = strLine.IndexOf(")
strResult = strLine.Substring(intFirstBracket + 1, intLastBracket - intFirstBracket - 1)
Return CInt(strResult)
End Function
Private Function GetMinutes(ByVal strLine As String) As String
Dim strResult As String = ")
strResult = strLine.Substring(intColons + 1, 2)
Return (strResult)
End Function
Private Function GetHours(ByVal strLine As String) As String
Dim strResult As String = ""
Dim intColons As Integer = strLine.IndexOf("
Dim intColons As Integer = strLine.IndexOf(")
strResult = strLine.Substring(0, intColons)
Return (strResult)
End Function
Private Function NewTimeMinutes(ByVal strDuration As String, ByVal strMinutes As String) As String
Dim strResult As String = "")
strResult = strLine.Substring(intColons + 1, 2)
Return (strResult)
End Function
Private Function GetHours(ByVal strLine As String) As String
Dim strResult As String = ""
strResult = CStr(CInt(strHours))
Return (strResult)
End Function