Hi,
My suggestion was instead using DirectCast() as your casting try to use the CType(), somebody already written some article on this
here's some example
DirectCast vs. CType[
^] (Im not the owner of this article)
But if its not still get the answer, maybe you can post which line the error occured when you run your program? for easy tracing here
I hope this help you on your problem
Regards,
Joven