Find Using Wildcard

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • gemini1617
    New Member
    • Mar 2008
    • 2

    Find Using Wildcard

    Hi, I am very new to visual basic and am using a select case statement with something called fSort. I found the code on a website but I need to modify it a little. I have a phrase and want to replace it with another phrase kind of like a Find and Replace tool. I have:

    Case "doesn't exist in Boston", "doesn't exist in New York", "doesn't exist in Atlanta"
    fSort = "doesn't exist"

    but there are a ton more cities I want to include in the case statement so instead of typing one long case statement I want to know if I can use a wild card or wild character to replace the city name. For instance:

    Case "doesn't exist in *wildcard*"
    fSort = "doesn't exitst"

    Can I do something like that?
    Thanks.
  • missinglinq
    Recognized Expert Specialist
    • Nov 2006
    • 3533

    #2
    Gemini1617, if you're saying that regardless of the city name, you want fSort to equal "doesn't exist" if the beginning of your field is "doesn't exist in" then, assuming the textbox holding this phrase is YourTextBox, you can use the example NeoPa just posted.

    Code:
    Select Case True
      Case  Left(Me.YourTextBox,16) = "doesn't exist in"
    	fSort = "doesn't exist"
    End Select
    Welcome to TheScripts!

    Linq ;0)>

    Comment

    • gemini1617
      New Member
      • Mar 2008
      • 2

      #3
      Linq,
      Thank you, it worked!

      Comment

      • missinglinq
        Recognized Expert Specialist
        • Nov 2006
        • 3533

        #4
        Glad we could help!

        Linq ;0)>

        Comment

        • NeoPa
          Recognized Expert Moderator MVP
          • Oct 2006
          • 32656

          #5
          Gemini,

          Welcome to TheScripts, but please don't post your question in somebody else's thread in future.

          I have split this away from Understanding the Select Case Statement and into its own thread now.

          Comment

          • NeoPa
            Recognized Expert Moderator MVP
            • Oct 2006
            • 32656

            #6
            Remember too, a Select Case statement is only warranted if you have multiple situations to handle. If you simply want to execute the logic you mention, you can use :
            Code:
            If LCase(Left(YourTextBox, 17)) = "doesn't exist in " Then _
                fSort = "doesn't exist"

            Comment

            Working...