Solved

Why won't this work?

Posted on 2001-06-13
11
207 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
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 50 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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 27

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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 utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

867 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now