On Condensing Code (1 Viewer)

Mile-O

Back once again...
Local time
Today, 14:10
Joined
Dec 10, 2002
Messages
11,316
I'm hopeless with ANDs and ORs in conditions when it comes to SELECT CASE and IF...THEN...ELSE statements.

Can anyone help to condense this code?

Code:
    If (datEndDate - datStartDate) = 0 Then
        CalculateDaysToResolve = 1
    Else
        For intCounter = 0 To (datEndDate - datStartDate) Step 1
            Select Case datStartDate + intCounter
                Case Is = datEaster - 2
                    ' do not increment
                Case Is = datEaster + 1
                    ' do not increment
                Case Is = datMayDay
                    ' do not increment
                Case Is = datSpring
                    ' do not increment
                Case Is = datAugust
                    ' do not increment
                Case Is = datChristmas
                        ' do not increment
                Case Is = datBoxingDay
                        ' do not increment
                Case Is = datNewYear
                        ' do not increment
                Case Is = datJanuary Then
                        ' do not increment
                Case Else
                        Select Case WeekDay((datStartDate + intCounter))
                            Case Is = 1 ' Sunday
                                ' do not increment
                            Case Is = 7 ' Saturday
                                ' do not increment
                            Case Else
                                CalculateDaysToResolve = CalculateDaysToResolve + 1
                        End Select
            End Select
        Next intCounter
    End If
 
Last edited:

PaddyIrishMan

Registered User.
Local time
Today, 14:10
Joined
Jun 5, 2002
Messages
166
Mile-O-Phile,
Multiple expressions can be used in a single line when seperated by commas - i.e.


Case Is = datEaster - 2
' do not increment
Case Is = datEaster + 1
' do not increment
Case Is = datMayDay
' do not increment
Case Is = datSpring

Could be:
Case Is = datEaster-2, datEaster+1, datMayDay, datSpring
'do not increment

That should help for a start.
regards,
Patrick
 

Mile-O

Back once again...
Local time
Today, 14:10
Joined
Dec 10, 2002
Messages
11,316
Thanks for that;

I'd tried doing

Case Is = ((datEaster - 2) OR (datEaster + 1) OR (datMayDay)) etc
' do not increment

but it was returning different values.

I'll try that when I get a chance.
 

Users who are viewing this thread

Top Bottom