0

I want to check every string in indexpage string witf If. This is indexpage

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

I've tryed parentheses, OrElse but it didn't worked.. And It's not a problem about If function. It still gives me this error when I try it without If function...

The Error:

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

Additional information: Conversion from string "string1" to type 'Boolean' is not valid.
6
  • What would you expect indexpage to contain after such an assignment? Commented Sep 23, 2015 at 11:37
  • Or are you saying you want to check if indexpage is already equal to either one of those strings? Commented Sep 23, 2015 at 11:38
  • In that case: possible duplicate of Check whether a string is not equal to any of a list of strings Commented Sep 23, 2015 at 11:40
  • Oops - that one is if it's not in the list of strings - your Q is the same but without the Not. Commented Sep 23, 2015 at 11:41
  • You'll need an if statement. Commented Sep 23, 2015 at 11:45

1 Answer 1

1

Thanks to James Thorpe, I found the answer.

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

And the If function

    If testAgainst.Contains(WebControl1.Source.ToString) Then
        ' code
    Else
        ' code
    End If
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.