as you do not show the types of your variables, can not give a definitive answer
what type is notfoundcnt?
what type is tempname?
try an explicit type conversion to avoid type mismatch
maybe the array is numeric? therefore can not accept a string