Arg81
Well-known member
Using Arrays to Calculate - RESOLVED
In my .net 1.1 App, jmcilhinney helped me put together a routine that allowed me to display 2 "time" calculations on my form.
The original post can be found here:
http://www.vbdotnetforums.com/showthread.php?t=4579
Here is the code I'm using
However, now that I'm redeveloping my app in .net 2.0, this routine no longer works, and I get the error;
"Failed to compare two elements in the array."
Can anyone please offer some advice on this?
Regards,
PS - there may be another way in .net 2.0 , I've attached a screenshot to show exactly what I am trying to acomplish.
In my .net 1.1 App, jmcilhinney helped me put together a routine that allowed me to display 2 "time" calculations on my form.
The original post can be found here:
http://www.vbdotnetforums.com/showthread.php?t=4579
Here is the code I'm using
VB.NET:
[code]
Private Sub CalculateTime()
Dim requestTimes As New SortedList
Dim requestProperties As ArrayList
Dim revisionTimes As SortedList
For Each row As DsDevelopment.DWR_WorkDataRow In Me.DsDevelopment.DWR_Work.Rows
If requestTimes.ContainsKey(row.DWRNumber) Then
'Get the existing entry for this request
requestProperties = DirectCast(requestTimes(row("DWRNumber")), ArrayList)
Else
'add a new entry for this request
requestProperties = New ArrayList(New Object() {0D, New SortedList})
requestTimes.Add(row("DWRNumber"), requestProperties)
End If
'add the time spent to the running total of the request
requestProperties(0) = CDec(requestProperties(0)) + CDec(row("TimeSpent"))
'get the list of times for each revision for the current request
revisionTimes = DirectCast(requestProperties(1), SortedList)
If revisionTimes.ContainsKey(row("RevisionNumber")) Then
'add the time spent to the running total for the revision
revisionTimes(row("RevisionNumber")) = CDec(revisionTimes(row("RevisionNumber"))) + CDec(row("TimeSpent"))
Else
'add a new entry for this revision
revisionTimes.Add(row("RevisionNumber"), CDec(row("TimeSpent")))
End If
Next row
If Me.DsDevelopment.DWR_Work.Rows.Count = 0 Then
Me.lblTSTimeDWR.Text = 0
Else
If Me.lblTSDWR.Text <> String.Empty AndAlso Me.lblTSRevNo.Text <> String.Empty Then
Me.lblTSTimeDWR.Text = DirectCast(requestTimes(CInt(Me.lblTSDWR.Text)), ArrayList)(0).ToString()
End If
End If
If grdEmployeeHours.Columns("TimeSpent").Text = "" Then
Me.lblTSRevTime.Text = 0
Else
If Me.lblTSDWR.Text <> String.Empty AndAlso Me.lblTSRevNo.Text <> String.Empty Then
Me.lblTSRevTime.Text = DirectCast(DirectCast(requestTimes(CInt(Me.lblTSDWR.Text)), ArrayList)(1), SortedList)(CInt(Me.lblTSRevNo.Text)).ToString()
End If
End If
End Sub
However, now that I'm redeveloping my app in .net 2.0, this routine no longer works, and I get the error;
VB.NET:
[FONT=Arial][COLOR=#0000ff]at System.Int16.CompareTo(Object value)[/COLOR][/FONT]
[FONT=Arial][COLOR=#0000ff]at System.Collections.Comparer.Compare(Object a, Object b)[/COLOR][/FONT]
[FONT=Arial][COLOR=#0000ff]at System.Array.BinarySearch(Array array, Int32 index, Int32 length, Object value, IComparer comparer)</ExceptionString></InnerException></Exception></TraceRecord>[/COLOR][/FONT]
"Failed to compare two elements in the array."
Can anyone please offer some advice on this?
Regards,
PS - there may be another way in .net 2.0 , I've attached a screenshot to show exactly what I am trying to acomplish.
Last edited: