Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    LA2
    LA2 is offline
    New to the CF scene
    Join Date
    Jan 2005
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    ASP Help (with search function) Please!!

    Here is a part of my code used in a search function:


    Function InstrWord(start, Text, search, compareMethod)
    Dim index
    Dim charcode
    InstrWord = 0
    index = start - 1
    Do
    index = Instr(index + 1, Text, search, compareMethod)
    If index = 0 then exit function
    If index > 1 then
    charcode = asc(ucase(mid(Text, index - 1, 1)))
    else
    charcode = 32
    end if
    If charcode < 65 or charcode > 90 then
    charcode = asc(ucase(mid(Text, index + len(search), 1)) & " ")
    If charcode < 65 or charcode > 29 then
    InstrWord = index
    Exit Function
    End If
    End If
    Loop

    End Function



    I'm getting an 'Invalid_use_of_Null' error on line 66, which is:


    charcode = asc(ucase(mid(Text, index + len(search), 1)) & " ")


    Any clue why? This code was working fine some time ago. I can't think of anything I've changed to create this error, but I've obviously done something
    Last edited by LA2; 01-08-2005 at 01:21 AM.

  • #2
    Senior Coder
    Join Date
    Apr 2003
    Location
    England
    Posts
    1,192
    Thanks
    5
    Thanked 13 Times in 13 Posts
    you could stop this error with
    If NOT IsNull(...) Then
    [do stuff]
    End If

    i expect it is thrown by trying to find the length of a null value or starting the mid at a null value

    what exactly is that code supposed to do because i cant think why it would be used

  • #3
    LA2
    LA2 is offline
    New to the CF scene
    Join Date
    Jan 2005
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hmm - thanks Ghell... I'm really not sure why most of it's included. I'm a beginner trying to make sense of someone elses work. Care to 'clean it up' a little? Please?!!!

    Here's the entire coding... this is the search box on the main page:

    <form name="frmJump" method="post" action="csearch.asp">
    <input name="keyword" type="text" id="keyword" size="15">
    <input name="btnSearch2" type="submit" id="btnSearch2" value="Search"></form>


    - certainly don't see anything wrong there. Then here's the entire content of the search results page (minus some html formatting):

    <%
    Function InstrWord(start, Text, search, compareMethod)
    Dim index
    Dim charcode
    InstrWord = 0
    index = start - 1
    Do
    index = Instr(index + 1, Text, search, compareMethod)
    If index = 0 then exit function
    If index > 1 then
    charcode = asc(ucase(mid(Text, index - 1, 1)))
    else
    charcode = 32
    end if
    If charcode < 65 or charcode > 90 then
    charcode = asc(ucase(mid(Text, index + len(search), 1)) & " ")
    If charcode < 65 or charcode > 90 then
    InstrWord = index
    Exit Function
    End If
    End If
    Loop

    End Function

    strSQL = "select * from ctbl ORDER BY ctitle"
    strCon = "Provider=Microsoft.JET.OLEDB.4.0; Data Source = " & server.mappath("../**/**.mdb") & ";"
    set db = server.createobject("adodb.connection")
    set rs = server.createobject("adodb.recordset")
    db.open strCon
    rs.open strSQL, strCon
    %>

    <html>
    <head>
    <title>Search Results</title>
    </head>
    <body>

    <span class="heading">Search results:</font></span><blockquote>
    <p>The search term <i><b><%=request.form("keyword")%></b></i> returned:</p>

    <%
    if request.form("keyword") <> "" then
    emptyresults = "yes"
    Do while not rs.EOF
    if InstrWord(1, rs("ctitle"), request.form("keyword"), vbTextCompare) or InstrWord(1, rs("cdesc"), request.form("keyword"), vbTextCompare) or InstrWord(1, rs("objectives"), request.form("keyword"), vbTextCompare) or InstrWord(1, rs("topics"), request.form("keyword"), vbTextCompare) then
    emptyresults = "no"
    %>
    <p bgcolor="<%=categoryColor%>"><a href="cview.asp?cid=<%=rs("cid")%>"><%=rs("cid")%> &nbsp; <%=rs("ctitle")%></a></p>
    <%end if
    %>
    <%rs.MoveNext
    Loop%>
    <%if emptyresults = "yes" then%>
    <P>no ctbl found - <a href="csearch.asp">search again</a></P>
    <%end if
    else%>
    <P>you did not enter a search keyword - <a href="search.asp">try again</a></P>
    <%end if%>
    </blockquote>


    </body>
    </html>

    <%
    rs.close
    db.close
    set rs = nothing
    set db = nothing
    %>

  • #4
    Senior Coder
    Join Date
    Apr 2003
    Location
    England
    Posts
    1,192
    Thanks
    5
    Thanked 13 Times in 13 Posts
    i think the function looks for a string inside another string, ie
    searching for hell in hello, its 4 long so it checks hell and ello for it

    as you are running from a database i would just use the like condition of the where clause (http://www.w3schools.com/sql/sql_where.asp)

    this could be
    Code:
    SELECT * FROM ctbl WHERE ctitle LIKE '%" & Request.Form("keyword") & "%' OR ..... ORDER BY ctitle
    im not really sure about how good this is, i have only used it once and it wouldnt return anyhting if the keyword was under 3 characters long, ie if you searched for "a" in "would you like to play a game?" it would throw an error but "play" worked fine *shrugs*


  •  

    Posting Permissions

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