Can you elaborate on "it's not working"?
Saying that something "is not working" is actually one of the least helpful phrases to use on a forum, especially when dealing with code. Did the code not compile? Did it run, but do something unexpected? Did it freeze mid-run? Does it generate error "XXX: Important message you should relay to forum"?
I tested out the code in the link, and it seems to work ok. If you can elaborate on what you didn't like about this particular solution, it will help us in creating a new one.