Forum Moderators: open

Message Too Old, No Replies

Invalid use of Null: 'Split'

VBScript runtime error '800a005e'

         

KRMwebdesign

10:31 pm on Jan 18, 2010 (gmt 0)

10+ Year Member



I have 2 different pieces of code and neither of them work. If I enter the first piece of code it will never show up what is in the database field regardlesss and if I enter the second piece it's okay if there is something in the dbase field but I get an error if there are no skills entered into the field. Error = Microsoft VBScript runtime error '800a005e'

Invalid use of Null: 'Split'

/mypage.asp, line 131

I wonder can someone help me here?

------------------------------------
First piece of code
------------------------------------

<% if NOT RsMembers.EOF then

Dim myKeywordArray
myKeywordArray = Split(RsMembers("mSkills"), ",")

if isarray(myKeywords) then

For i = 0 to UBound(myKeywordArray)
response.write "<a href='membersearch.asp?mSkills=" & Trim(myKeywordArray(i)) & "'>" & Trim(myKeywordArray(i)) & "</a>, "
Next

Else

response.write ("No skills entered.") End if
End if %>

------------------------------------
Second piece of code
------------------------------------

<% if NOT RsMembers.EOF then

Dim myKeywordArray
myKeywordArray = Split(RsMembers("mSkills"), ",")

For i = 0 to UBound(myKeywordArray)
response.write "<a href='membersearch.asp?mSkills=" & Trim(myKeywordArray(i)) & "'>" & Trim(myKeywordArray(i)) & "</a>, "
Next

Else

response.write ("No skills entered.") End if
%>

Demaestro

10:36 pm on Jan 18, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



From what I can tell the error you are getting is because you have null value in the RsMembers("mSkills") results... since it has a null value you can't call the split() function on it.

I am not sure on the exact syntax, it has been a while for me and VB but you want to test to see if the array has a null value first... something like

if RsMembers("mSkills") != Null then
Dim myKeywordArray
myKeywordArray = Split(RsMembers("mSkills"), ",")
else
response.write ("No skills entered.")

If RsMembers("mSkills") should never be Null then you need to look at why it is getting a null value.

KRMwebdesign

10:46 pm on Jan 18, 2010 (gmt 0)

10+ Year Member



Oh I see what you mean. What I want to do though is cater for a null value. So if "mSkills" is not null then create the array. Is that it?

Demaestro

10:52 pm on Jan 18, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Yes that is correct. You just test it to see if it is null.

Another way of doing this is by error handling, I am not sure which is best suited for you in this case. I would do the test rather than the error handling, but if using error handling makes more sense for your app it would look something like this:

(again this is pseudo-code, syntax is wrong)

try
myKeywordArray = Split(RsMembers("mSkills"), ",")
except error E
if E.message = "Invalid use of Null: 'Split' then
myKeywordArray = []

.......

You can also set the array to be empty and then pass it to your loop... something like this...

Dim myKeywordArray
if RsMembers("mSkills") != Null then
myKeywordArray = Split(RsMembers("mSkills"), ",")
else
myKeywordArray = []

Play around with what method works best for the rest of your code... if you have more questions please ask.

KRMwebdesign

10:29 am on Jan 19, 2010 (gmt 0)

10+ Year Member



Thanks for the help Demaestro. I'm still having some problems but I'll work it out. Thanks again.