Vbscript runtime error 800a005e

Function GetNumberKids(myNode,myArray)

       Dim myTemp

       myTemp=""

       myCount = 0

       Dim i

       'Look for kids

 

       for i = lbound(myArray,2) to ubound(myArray,2)

 

              if cstr(myArray(1,i))=cstr(myNode) then ' we found a kid

                     if myTemp="" then

                           myTemp= cstr(myArray(0,i))

                     else  

                           myTemp=       myTemp & "," & cstr(myArray(0,i))

                     End if

                     myCount=myCount+1

              End if

       Next 'i

       GetNumberKids = myTemp

End Function
sheekhaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

regmigrantCommented:
you haven't said where the error occurs but generally this is related to null values so I would guess its one of the cstr functions not handling a null in the array

have you tried putting a break on the mytemp="" line then stepping through the code and checking the variable contents at the point where it fails?
1
sheekhaAuthor Commented:
if cstr(myArray(1,i))=cstr(myNode) then error of this line cstr invalid
0
regmigrantCommented:
check the values of myArray(1,i) and myNode - one or both of them is probably null. you can check for null with
If isnull(myNode)

which will return true if myNode is null
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

sheekhaAuthor Commented:
Thanks. can you explain all the code?
0
regmigrantCommented:
try the following changes which will skip over a value of i with a null in the array and skip the loop altogether if MyNode is null.

This should remove the runtime error but you need to figure out how to deal with Nulls properly in the rest of the code; for example: if mynode is null then obviously there is nothing to find - so is this a valid value or would you expect it to be treated as a zero length string instead?


       

If isnull(myNode) then
   debug.print "myNode is null!!"
   Stop
Else

for i = lbound(myArray,2) to ubound(myArray,2)

          if isnull(myArray(1,i)  then                        ' check for null values and skip this value of i if found

               debug.print "invalid data at " & i 
         else

              if cstr(myArray(1,i))=cstr(myNode) then ' we found a kid

                     if myTemp="" then

                           myTemp= cstr(myArray(0,i))

                     else   

                           myTemp=       myTemp & "," & cstr(myArray(0,i))

                     End if 

                     myCount=myCount+1

              End if 
         Endif
       Next 'i
Endif
       GetNumberKids = myTemp

End Function

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Martin LissOlder than dirtCommented:
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.