2015-09-23 86 views
0

我想檢查中的每個字符串索引頁 string witf If。這是indexpage多個字符串在一個字符串中或者

Dim indexpage As String = "string1" Or "string2" 

我tryed括號,OrElse運算,但它並沒有奏效。而這不是一個關於如果函數問題。它仍然給我,當我嘗試沒有如果函數這個錯誤...

的錯誤:

An unhandled exception of type 'System.InvalidCastException' occurred in Microsoft.VisualBasic.dll 

Additional information: Conversion from string "string1" to type 'Boolean' is not valid. 
+0

什麼你所期望的'indexpage'這樣的轉讓後,包含哪些內容? –

+0

還是你說你想檢查'indexpage'是否已經等於這些字符串中的任何一個? –

+0

@JamesThorpe是的。 – Eren

回答

1

感謝詹姆斯·索普,我找到了答案。

Dim testAgainst As String() = {"02","03","06","07"} 

和IF函數

If testAgainst.Contains(WebControl1.Source.ToString) Then 
     ' code 
    Else 
     ' code 
    End If 
相關問題