Question : Incrementing a date value in a Do..Until Loop

Hi, I have a couple of date values in a vb.net app that I am trying to parse through and subtract out non-office hours.  My problem is that the date value is not actually changing when I try to subtract a day at the end of each loop cycle, so it is stuck in an endless loop.  Any ideas?  Whether it's a simple error that I'm not seeing or a better process altogether, I'm open to any suggestions.  Thanks in advance!
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
Dim iDate As Date = EndDate
Dim iEndDate As Date = EndDate

                    Do Until iDate.Date = StartDate.Date
                        Select Case iDate.DayOfWeek
                            Case DayOfWeek.Monday
                                iEndDate.AddHours(-14)
                            Case DayOfWeek.Tuesday
                                iEndDate.AddHours(-14)
                            Case DayOfWeek.Wednesday
                                iEndDate.AddHours(-14)
                            Case DayOfWeek.Thursday
                                iEndDate.AddHours(-14)
                            Case DayOfWeek.Friday
                                iEndDate.AddHours(-14)
                            Case DayOfWeek.Saturday
                                iEndDate.AddHours(-24)
                            Case DayOfWeek.Sunday
                                iEndDate.AddHours(-24)
                        End Select

                        iDate.AddDays(-1)
                    Loop

                    dim ts as TimeSpan = iEndDate - StartDate

Answer : Incrementing a date value in a Do..Until Loop

You are not setting the date back.  your code has iDate.AddDays(-1)

it should be iDate = iDate.AddDays(-1)

Random Solutions  
 
programming4us programming4us