Exception occured error

J

J. Muenchbourg

I'm getting an Exception occured error on line 4 (For i =1...)

<% Function ProperCase(strIn)
strOut = ""
boolUp = True
For i = 1 To Len(strIn)
c = Mid(strIn, i, 1)
if c = " " or c = "'" or c = "-" then
strOut = strOut & c
boolUp = True
Else If boolUp Then
tc = Ucase(c)
Else tc = LCase(c)
End If
strOut = strOut & tc
boolUp = False
End If
Next
ProperCase = strOut
End Function %>

this function is put into an include file, and it uppercases a horse's
name's first letter, and lowercases the rest, being called this way:

response.write left(ProperCase(rs1("horsename")),14)

What happens is when there are no more horse's names to be drawn from
the database, that's when I get this Exception occured error

thx for help
Muench
 
B

Bob Barrows

Add a line to verify that the Len(strIn) > 0
J. Muenchbourg said:
I'm getting an Exception occured error on line 4 (For i =1...)

<% Function ProperCase(strIn)
strOut = "" IF Len(strIn) > 0 then
boolUp = True
For i = 1 To Len(strIn)
c = Mid(strIn, i, 1)
if c = " " or c = "'" or c = "-" then
strOut = strOut & c
boolUp = True
Else If boolUp Then
tc = Ucase(c)
Else tc = LCase(c)
End If
strOut = strOut & tc
boolUp = False
End If
Next End If
ProperCase = strOut
End Function %>
Bob
 
A

Aaron Bertrand - MVP

response.write left(ProperCase(rs1("horsename")),14)

Did you try:

response.write(rs1("horsename"))

Is there a value there?
What happens is when there are no more horse's names to be drawn from
the database, that's when I get this Exception occured error

Maybe you should be testing for EOF!??!? How are you looping through these
horsenames? Maybe you could show more code, and we could show you how to
fix it...
 
T

Tom B

I'm sure you've had a similar problem before. What happens if the horsename
is null?
If it is null then your line Len(strIn) is asking for the length of a null
string... which is invalid.
You need to test for null first.

Function ProperCase strIn
if isNull(strIn) then Exit Function

OR

Function ProperCase strIn
strIn=strIn & "" 'That'll turn a null into an empty string. But
be careful, an empty string may not work with the rest of your code.



OR

response.write left(ProperCase(rs1("horsename") & ""),14) ' Again, empty
string
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,902
Latest member
Elena68X5

Latest Threads

Top