[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Why won't this work?

Posted on 2001-06-13
11
Medium Priority
?
240 Views
Last Modified: 2010-05-02
'I would like to see 2 matches
'case1 and case4

Const Case1 = "ABC def"
Const Case2 = "abcd ef"
Const Case3 = "abc def"
Const Case4 = "def abc"

Private Sub Command1_Click()
Dim i As Integer
Dim x As String
x = "ABC def and deff and defab def abc deff abcd eg"
For i = 1 To 4
Select Case i
Case 1
If x Like Case1 Then MsgBox Case1 & " Found a match"
Case 2
If x Like Case2 Then MsgBox Case2 & " Found a match"
Case 3
If x Like Case3 Then MsgBox Case3 & " Found a match"
Case 4
If x Like Case4 Then MsgBox Case4 & " Found a match"
End Select
Next i
End Sub
0
Comment
Question by:Juilette
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
11 Comments
 
LVL 4

Expert Comment

by:mcmahon_s
ID: 6188644
This looks like really weird code, what are you trying to do?
0
 
LVL 2

Accepted Solution

by:
Microsoft earned 150 total points
ID: 6188661
your going about this the wrong way, your code to me looks like that your are attempting to detect when your type a case which has these conditions

ABC DEF
or
abcd ef
or
abc de

if this is the case your dont need to be using case.

you need to be using mid string

first of all am i write in what im saying


0
 
LVL 1

Expert Comment

by:alaplume
ID: 6188679
Use wildcards * and #
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 2

Expert Comment

by:Microsoft
ID: 6188700
have a look at this link, download the code this will show you how to use case select correctly.

http://www.freevbcode.com/ShowCode.Asp?ID=1027
0
 
LVL 2

Expert Comment

by:Microsoft
ID: 6188721
alaplume dont answer the question use comment, you have now locked the question for other users to comment.

this is normally classed as rude, you will get alot of stick from other EE users if you take this method.

I would decline his answer Juliette so that others can give you a solution to your question

he hasnt offered a correct answer, he has told you how to solve for problem and what he has suggested wouldn't work.

cheers
andy
0
 
LVL 2

Expert Comment

by:Microsoft
ID: 6188729
actually it probley makes sence for his stupid answer. he's never had an answer accepted.

lol

meow....
0
 
LVL 4

Author Comment

by:Juilette
ID: 6188976
that is where I am having the problem...in the use of the wild cards..the Case select works..for example if I change my string to one of the cases it will message me with found.
What I can't get to work is the Like Function?

If you are going to give an answer then you should give an answer...I know how to use wild cards in some instances but in this particular one I'm lost.
0
 
LVL 4

Author Comment

by:Juilette
ID: 6188983
the like function whoudl fine one occurance of your string within a string.
so if "abc" like "abc"  then I have a match
In simple terms I want to fine "abc" in "ghijf as abc cda"

That is my problem...I should not have to use mid since that is slower as it has to read each character...Like Function is what I want...I just can't figure it out.

Example:
If "1234" Like "*#*" Then MsgBox "like"
If "1234 abc" Like "*1234*" Then MsgBox "OK"
both of these work but when I use a variable, I don't know how to use the function.
0
 
LVL 4

Author Comment

by:Juilette
ID: 6189023
Microsoft, I am giving you the points as it's not worth the time to try and retrieve them...at least you put out an effort.

For anyone who searches this code, the corrected code is here...I figured it out...dumb old concatenation...
Const Case1 = "ABC def"
Const Case2 = "abcd ef"
Const Case3 = "abc def"
Const Case4 = "def abc"

Private Sub Command1_Click()

Dim i As Integer
Dim x As String
x = "ABC def and deff and defab def abc and abcd eg"
For i = 1 To 4
Select Case i
Case 1
If x Like "*" & Case1 & "*" Then MsgBox Case1 & " Found a match"
Case 2
If x Like "*" & Case2 & "*" Then MsgBox Case2 & " Found a match"
Case 3
If x Like "*" & Case3 & "*" Then MsgBox Case3 & " Found a match"
Case 4
If x Like "*" & Case4 & "*" Then MsgBox Case4 & " Found a match"
End Select
Next i
End Sub
0
 
LVL 28

Expert Comment

by:Ark
ID: 6189024
Hi
Why not to use Instr function instead of Like?

If InStr(1,x,Case1,vbBinaryCompare) Then MsgBox...

Cheers
0
 
LVL 4

Author Comment

by:Juilette
ID: 6189029
Microsoft, I am giving you the points as it's not worth the time to try and retrieve them...at least you put out an effort.

For anyone who searches this code, the corrected code is here...I figured it out...dumb old concatenation...
Const Case1 = "ABC def"
Const Case2 = "abcd ef"
Const Case3 = "abc def"
Const Case4 = "def abc"

Private Sub Command1_Click()

Dim i As Integer
Dim x As String
x = "ABC def and deff and defab def abc and abcd eg"
For i = 1 To 4
Select Case i
Case 1
If x Like "*" & Case1 & "*" Then MsgBox Case1 & " Found a match"
Case 2
If x Like "*" & Case2 & "*" Then MsgBox Case2 & " Found a match"
Case 3
If x Like "*" & Case3 & "*" Then MsgBox Case3 & " Found a match"
Case 4
If x Like "*" & Case4 & "*" Then MsgBox Case4 & " Found a match"
End Select
Next i
End Sub
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Suggested Courses

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question