VB.NET Select Case - what is the correct statement?

Brandon picture Brandon · Jan 24, 2013 · Viewed 9.8k times · Source

Why doesn't the following code work?

Private Function resolveSiteName(ByVal plantName As String, ByVal siteName As String) As Integer
    Dim siteId As Integer = Nothing
    Dim fullName As String = plantName & siteName
    Select Case fullName
        Case fullName.Contains("Example" And "Example2" And "Example3")
            siteId = 0
    End Select
    Return siteId
End Function

I'm guessing my Select Case fullName is wrong, because when debugging it, the conditions are met and it just skips over assigning the siteId.

I also tried just this

Case fullName.Equals("Exactly what full name is")

just to test to see if that would work...and it still skipped over the assigning part.

What am I missing here?

Answer

Ric picture Ric · Jan 24, 2013

This should work too:

Select Case fullName
   Case "Example", "Example2", "Example3"
      siteId = 0
End Select