2015-09-23 85 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 
相关问题