Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 204
Default General tips for good code formatting

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.
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1,549
Default General tips for good code formatting

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.
  #3   Report Post  
Posted to microsoft.public.excel.misc
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.

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 8,520
Default General tips for good code formatting

Congrats!!!...Check out the below link on coding practices.....(will be useful)

http://blogs.msdn.com/excel/archive/...practices.aspx

Below are some other tips for a starter level....

--As Jim mentioned include lot of comments. I personally include comments
for each variables I declare; I had experiences spending hours to identify
what the variable do..

intRaceCounter 'Number of races
dtStartTime 'Start time of race

--Using data type prefix for variables

lngRow denotes data type Long
varTemp denotes that the variable is of Variant data type
strRaceName denotes that the variable is String variable
arrData denotes that the variable is an Array

User forms with frmStartUp, frmCalculations, frmSettings
Textboxes prefixed with txtStartTime, txtEndTime
Comboboxes with cmbStartTime, cmbEndTime
Command Buttons with cmdSubmit, cmdOK

--Naming of variables..While coding all of us prefer to use short variables
names eg (x,y,c,i are commonly used) but in the long run that will not
help..Name it as below so as to reflect the variable type and the purpose...

strFirstName
dtStartDateTime
dtStopDateTime


If this post helps click Yes
---------------
Jacob Skaria


"NDBC" wrote:

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.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Date format for general formatting rrupp Excel Discussion (Misc queries) 5 July 15th 08 10:19 PM
change formatting from general to date JH Excel Discussion (Misc queries) 2 February 9th 07 03:21 PM
Sources of Excel Tips, Tricks & Code John James Excel Discussion (Misc queries) 6 April 3rd 06 08:51 PM
Number formatting: General + separator? John Persons Excel Discussion (Misc queries) 12 November 7th 05 08:36 PM
Formatting General to Number RJohnson701CTS Excel Discussion (Misc queries) 7 July 27th 05 04:16 PM


All times are GMT +1. The time now is 09:00 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"