StrComp Function Help?

Results 1 to 3 of 3

Thread: StrComp Function Help?

  1. #1
    Jeff Kovach Guest

    Default StrComp Function Help?

    In the following statement, why wouldn&#039t StrComp = 0?<BR><BR>Dim strString1<BR>strString1 = "Apples C Pears"<BR><BR>If StrComp(strString1,"Like &#039%[s]C[s]%&#039",1) = 0 then<BR>...<BR>End If<BR><BR>What I need to say is, if there is a letter "C" in string1 surrounded by spaces, then let the function = 0 or true if using another function. Also, I&#039ve tried other ways of writing the string2 argument with no success since I&#039m using special characters.<BR><BR>Can anyone give me a real example?<BR>Sorry, folks. I&#039m just a beginner at VBScript.<BR><BR>Thanks,<BR>Jeff

  2. #2
    Eddie Campbell Guest

    Default RE: StrComp Function Help?

    You need to use Instr rather than StrComp.<BR><BR>Try this<BR>StrString1 = "Apples C Pears"<BR>If Instr(StrString1, " C ") = 0 then<BR>&#039 string was NOT found<BR>Else<BR>&#039 string WAS found<BR>End if

  3. #3
    Jeff Kovach Guest

    Default RE: StrComp Function Help?

    It&#039s getting close to what I need, but maybe I&#039m leaving out too much information for you. By the way, since InStr returns the position rather than 0 if it&#039s true, I need to say if &#062; 0.<BR><BR>Part of Code:<BR>...<BR><BR>If Instr(StrString1, " C ") &#062; 0 Then<BR>&#039string found. Return position<BR>Else<BR>&#039string not found<BR>End If<BR><BR>Here&#039s my problem: <BR>Users on a website fill in a form field named "Skills". Then, an SQL statement gets dynamically created depending on which fields they have selected as criteria from the form.<BR><BR>Problem: If the "Skills" field = "C" (C programming language) then it will find every word with the letter C in it, so I have to create a different scenario for users putting in that letter as a skill. Also, It could be embedded between other words(Java and C and VB). Or maybe it&#039s at the beginning(C and Java). As you can see, it gets tricky!<BR><BR>Part of code written:<BR><BR>If Skills &#060;&#062; "" Then<BR>IsWhere = 1<BR> <BR>&#039Strip double quotes; replace single quotes<BR>Skills = Replace(Request("Skills"),"""","")<BR>Skills = Replace(Skills,"&#039","&#039&#039")<BR> <BR>&#039Get rid of parenthesis <BR>Skills = Replace(Skills,"(","")<BR>Skills = Replace(Skills,")","")<BR> <BR>andTerms = split(Skills," ",-1,1)<BR>iUpperTerms = UBound(andTerms)<BR> <BR>For iLoop = LBound(andTerms) to iUpperTerms<BR> <BR>If InStr(Skills, " C ") &#062; 1 then &#039Problem line. doesn&#039t work.<BR> WhereClause = WhereClause & "(Skills LIKE &#039" & Trim(andTerms(iLoop)) & "[s,/]%&#039 " & _<BR> "OR (Skills LIKE &#039%[!a-z]" & Trim(andTerms(iLoop)) & "[!a-z]%&#039 " & _<BR> "AND Skills NOT LIKE &#039%[!a-z]C+%&#039) " & _<BR> "OR Skills LIKE &#039%[!a-z]" & Trim(andTerms(iLoop)) & "[s,/]%&#039 " & _<BR> "OR Skills LIKE &#039%[s,/]" & Trim(andTerms(iLoop)) & "[!a-z]%&#039)"<BR>Else<BR> WhereClause = WhereClause & "Skills LIKE &#039%" & _<BR>Trim(andTerms(iLoop)) & "%&#039"<BR>End If<BR> <BR>if iLoop &#060; iUpperTerms then <BR> WhereClause = WhereClause & " AND "<BR>end if<BR> <BR>Next<BR> WhereClause = WhereClause & " AND "<BR>End If<BR><BR>...<BR><BR>If it&#039s too confusing I apologize, the code works except for the one line noted above.<BR><BR>Thanks for your help!<BR>Jeff Kovach

Posting Permissions

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