Need help to figure out my logic flaw

  • Thread starter Thread starter aha_tom
  • Start date Start date
A

aha_tom

Guest
I got a table below. My code is to insert the missing dates and fill them with 0 hours.

581359


The way my code works:

First, create a new datatable with all dates from 8 Dec to 22 Dec and fill in all the dates with 0 hours.

Next, it will compare my original table with the new table. If the date matches, it will then fill the "Hours" column in the new datatable with the "Hours" value from my original table.

The critical bit to compare the tables looks like this:

indexNum = 0
For h = 0 To totalDays - 1
If the dates are the same in two table, apply logged hours to the new table, then move to next index
If CDate(OrigDataTable.Rows(indexNum).Item(0)).ToString("dd/MM/yyyy") = newDataTable.Rows(h).Item(0) Then
newDataTable.Rows(h).Item(1) = origDataTable.Rows(indexNum).Item(1)
Only if index number is smaller than the total rows of Original datatable minus 1
If indexNum < OrigDataTable.Rows.Count - 1 Then
indexNum += 1
Make sure todays data is entered
If CDate(OrigDataTable.Rows(indexNum).Item(0)).ToString("dd/MM/yyyy") = newDataTable.Rows(h + 1).Item(0) Then
newDataTable.Rows(h + 1).Item(1) = origDataTable.Rows(indexNum).Item(1)
End If
End If
End If

Next

The code has a flaw... Its output looks like below. As you can see, somehow the last days Hours column has not been updated with correct value. More strangely, If there is a value for 22 Dec (Tuesday), 21 Dec (Monday) Hours will update correctly... Can anyone point out what I have done wrong here?

581361


Continue reading...
 
Back
Top