I put one in the code archives almost a year ago that does what you want.
http://www.blitzbasic.com/codearcs/codearcs.php?code=1790
http://www.blitzbasic.com/codearcs/codearcs.php?code=1790
The Forum Archive is locked. These are the original blitzbasic.com forums, kept so their posts can still be read and searched. No new topics, replies or edits can be made here. To join the conversation, head over to the Blitz3D+ forums.