Results 1 to 3 of 3

Thread: Very quick question - how can i check if something exists in a string? (InStr)

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Dec 2000
    Posts
    1,195

    Very quick question - how can i check if something exists in a string? (InStr)

    If I did this:

    mystring = "Thewordyesisengravedinhere"

    How can i make an if statement that sends a messagebox if the word "yes" is in a string?

    I tried
    Code:
    mystring = "thewordyesisengravedinhere"
    If InStr("yes", mystring) Then
    MsgBox "Yes was found"
    Else
    MsgBox "Yes was not found"
    End If
    but it doesnt work.. anyone know?

  2. #2
    Matthew Gates
    Guest
    You are using the InStr function backwards.


    Code:
    mystring = "thewordyesisengravedinhere"
    If InStr(mystring, "yes") Then
    MsgBox "Yes was found"
    Else
    MsgBox "Yes was not found"
    End If

  3. #3
    Matthew Gates
    Guest
    You can also use the Like operator to find "yes."


    Code:
    mystring = "thewordyesisengravedinhere"
    If mystring Like "*yes*" Then
    MsgBox "Yes was found"
    Else
    MsgBox "Yes was not found"
    End If

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width