Results 1 to 20 of 23

Thread: Optimisation tips

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #11
    VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,709
    Location

    Yet Another Style Example

    Here is a little 13 line, (in original form,) function I picked up online and wanted in my Function library. The only edits I made to the OP's actual code are that in the Swap Numeric and Alpha section, he used the Mid function for both sides and I thought that it was more readable using the Right and Left functions. I also replaced all calls to the Len function with references to StrLen.

    I immediately rewrote the code in my preferred style, but I haven't used it yet. The four-mark comments act as section headers and are also the actual algorithm of the code. I write them, (the alorithms,) first when writing original code. All other comments show the reason why I chose to use a particular item or procedure to future maintainers

    I show the code in an image because VBAX imposes its own style, (especially white-space,) on any code inside Code Tags. You see different colors and Tab spaces than usual because I customized my VBA Editor using the VBA Menu>>Tools>>Options>>Editor Format.

    As you can see, it still needs a Boolean helper function, called in the Pre-Process Tests section, to handle very mixed strings, and the Error in Usage section needs completion.

    When understanding this code:
    First read the Four-Mark comments and you will know what the code is doing.
    Then it is easy to ignore the pale green comments while reading the actual code to see how it does it.
    Blue words indicate Decision procedures and Reddish show the operation.
    Last edited by SamT; 02-20-2014 at 08:54 AM.
    Please take the time to read the Forum FAQ

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •