user2087008
user2087008

Reputation:

Refactoring case select into if statement

I have the following code:

    Dim useFont As Font = e.Font
    Dim myBrush As Brush = Brushes.Black
    ' Determine the font to draw each item based on    
    ' the index of the item to draw. 
    If e.Index = 0 Or 7 Or 10 Or 13 Then
        useFont = New Font(e.Font, FontStyle.Bold)
    Else
        useFont = DefaultFont
    End If

    ' Select e.Index
    '    Case 0
    'useFont = New Font(e.Font, FontStyle.Bold)
    '    Case 7
    'useFont = New Font(e.Font, FontStyle.Bold)
    '   Case 10
    'useFont = New Font(e.Font, FontStyle.Bold)
    '    Case 13
    'useFont = New Font(e.Font, FontStyle.Bold)
    'End Select

The commented out code below is my old, working code. I thought I better rewrite it to make it more compact and readable, however I cannot work out how to perform the same function as the case select, as it just results in all my list items becoming bold. I don't know if I'm just misunderstanding the OR operator, and OrElse does not work either.

Can anybody give me some pointers in the right direction? Thanks.

Upvotes: 0

Views: 94

Answers (1)

peterG
peterG

Reputation: 1641

If e.Index = 0 Or e.Index= 7 Or e.index=10 Or e.index=13 Then

But you could equally have done

Case 0,7,10,13

Upvotes: 3

Related Questions