Just as an FYI we have a couple of UDFs that already do just about anything you could want or imagine with subnetting.

Please review the UDF forum or one of the mirror links.

http://www.gwspikval.com/jooel/UDF/

http://www.kixhelp.com/udfs/