View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.misc
NDBC NDBC is offline
external usenet poster
 
Posts: 204
Default General tips for good code formatting

Thanks Jim,

My biggest module is 41kb, so at least that part seems ok. I have 20
worksheets with varying amounts of formulas in them so I'm guessing that's
where the file size is coming from.

I already have a fair few notes in there as well but I might put a few more
in with regards to the why.



"Jim Cone" wrote:

I hope you don't have a module that is 5mb. <g
64kb seems to be a popular limit on size for a module.
(you can export it to a folder and check the size)

Lots of comments in your code explaining the why, not just the what,
will be helpful to you later. A few months from now, chances are
you won't understand the code unless you added comments to it.
Ken Getz ran some tests (several years ago) and stated that code
runs just as fast with comments as without.

Do you reset everything you altered before exiting?
(events/calculation...)
Are all the forms unloaded?
Do you have/need error handling?
Have you minimized the use of Global variables?
Does it compile?

Try...
Copying your code out to Notepad.
Delete the module.
Insert a new module.
Copy the code from Notepad and paste into the new module.
(may reduce your file size and clean things up some)
--
Jim Cone
Portland, Oregon USA



"NDBC"
wrote in message
...
I finally have my code working. I am trying to tidy it up for several reasons

1) so others can follow it
2) so it will run faster
3) so it is easier/quicker to edit
4) to reduce the risk of typing mistakes

So far I have implemented the option explicit statement and put in some
loops for repetitive code. I have also saved it as a web page and then saved
it back to an xls file to reduce file size (went from 9MB to 5MB). Is there
any risks with doing this.
Is there a website I can look at that outlines basic good practice for code
format.
Thanks again for everybodies input. My scoring program already far exceeds
my expectations of what I was aiming for when I first started. Unfortunately
the time taken to do it was the same.