[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

ASP If then using like

Posted on 2009-04-29
4
Medium Priority
?
441 Views
Last Modified: 2012-05-06
Please see my code below. I cannot get the LIKE clause to work with this if then statement. What am I doing wrong?
Thanks
If (rstimes.Fields.Item("Prodoption").Value)  LIKE "Triple%" Then
varused = 3
end if

Open in new window

0
Comment
Question by:wellsuited
  • 2
  • 2
4 Comments
 
LVL 10

Accepted Solution

by:
ALaRiva earned 2000 total points
ID: 24265073
You cannot use LIKE in an IF Statement.  LIKE is only valid in SQL.

You can use the InStr() Function though, to determine if "Triple" is in the value.

Try this:
If Instr(1,rstimes.Fields.Item("Prodoption").Value,"Triple") > 0 Then
varused = 3
end if

HTH
- Anthony
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 24265313
>>I cannot get the LIKE clause to work with this if then statement. What am I doing wrong?<<
That is because the Visual Basic Like operator is not supported in VBScript.  See here for a complete list of the differences between Visual Basic and VbScript:
http://msdn.microsoft.com/en-us/library/30593abb(VS.85).aspx

0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 24265337
Just a minor correction to the previous workaround (no points please):

If Instr(1, rstimes.Fields.Item("Prodoption").Value,"Triple", vbTextCompare) = 1 Then
   varused = 3
End If

You should also be able to use RegEx for the same result.
0
 
LVL 10

Expert Comment

by:ALaRiva
ID: 24265352
Thanks acperkins, I always forget that detail.
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

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

Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
Screencast - Getting to Know the Pipeline
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

830 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