Divide the program into discrete sections, then figure out what functionality (modules and/or subs) you'll need for each section. Design all necessary subs and perform proper testing; put together the sections and perform testing on these as well. Small programs can be thrown together willy-nilly, but larger programs will require several layers of coding and testing if you don't want to get into a terrible muddle.