Cry for help with ASP

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 :D
 
OK - I'm a little further on. I've discovered that the error is being caused by some of the fields that are being searched within the records not having any data in them. When I gave the fields with no data a token '.' the error disappeared.

I don't really understand why this is an invalid use of null though as in the access db I have the fields marked as being allowed to have a zero length...

Is there something I can add to the above code so that it will ignore any field that has zero data? It is obviously screwing up it's calculation there somehow, though it would probably help if I understood exactly what the code was doing 8)

Thanks in advance!!
 
InStr returns Null if the searched string is zero-length. Therefore index will be Null. In the line where you get the error, you try to add Null and another value, which is the invalid use.

This should fix the problem:
Code:
If index = 0 Or IsNull(index) then exit function
 
Back
Top