Jump to content
  • Advertisement
Sign in to follow this  
boolean

[web] ASP: splitting keywords into array

This topic is 4857 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have a search field which I am trying use to split the keywords into an array, based on spaces between keywords, then plug that into an SQL statement. For some reason when I run the code below, I get an 'Object required' error.
Dim i, sSearch, sArray
i=0
if sSearch <> "" then 
  sArray = split(sSearch," ")

   do while i<sArray.length
	  i = i+1
         sql = sql & " AND " 
      sql = sql & "Keywords LIKE '%" + sArray(i) + "'%"

  loop
   end if


Does it look like that code should work? Is there a good chance the error is being caused elswhere in the page? I am using an Access database for this.

Share this post


Link to post
Share on other sites
Advertisement
Hrmm..that looks to me like it should work, although i'm no pro.

Does it tell you what line the error is on? It should if you're using regular ASP with VBScript
(ensure show friendly error messages is disabled) I.E. = Tools->Interent Options->Advanced->Show Friendly HTTP error messages

ArchG

Share this post


Link to post
Share on other sites
sql = sql & "Keywords LIKE '%" + sArray(i) + "'%"


should be

sql = sql & "Keywords LIKE '%" + sArray(i) + "%'"


Notice position of apostrophe.

Share this post


Link to post
Share on other sites
If this is old-school asp 3.0, then the problem is .length. There's no .length property on arrays. It's retarted, but you have to do something like this:



function ArrayLength(a)
dim length
on error resume next
length = 0
if isArray(a) then
length = ubound(a) - lbound(a) + 1
end if
on error goto 0
ArrayLength = length
end function





If you try to do a ubound or lbound on something that is not an array or a zero-length array ( erase a ) then you will get an error. This is something that has annoyed me for years.

Share this post


Link to post
Share on other sites
This is VBScript you're working with.


i = 0
...
do while i<=UBound(sArray)
sql = sql & " AND "
sql = sql & "Keywords LIKE '%" + sArray(i) + "'%"
i = i + 1
loop


The array variable is not an object with properties and methods. Use UBound() to get the upper boundary of the array (and correct to <= since UBound returns the index of the last element, not the number of elements). Also move the increment to the end of the loop (you're skipping the first element, sArray(0)).

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!