Consulting

Results 1 to 4 of 4

Thread: Coding Efficiency (2)

  1. #1
    VBAX Regular
    Joined
    Apr 2019
    Location
    London
    Posts
    25
    Location

    Coding Efficiency (2)

    Hi,
    A couple of questions which relate to coding efficiency and best practices:

    1. I have seen a couple of comments from apparently knowledgeable people suggesting that an integer is best DIMed as long.
    Yet most example code I see, DIMs integers as Integer.
    Your thoughts?

    2. Looping with If . . . Then:
    If one has just 2 or 3 statements dependent on an IF condition, is it better to code as

    If [conditionA] Then
    statement 1
    statement 2
    End If

    OR
    If [conditionA] Then statement 1
    If [conditionA] Then statement 2


    I have many of this type of If . . . Then in a sub. Perhaps the small difference in coding adds up?

    Thank for your thoughts.

  2. #2
    VBAX Regular pike's Avatar
    Joined
    Dec 2007
    Location
    Alstonville, Australia
    Posts
    97
    Location
    Hi Kerry,
    integer or Long isn’t that important with memory in todays computers but helps on a small scale or when distinguishing between variables/numbers or if you have thousands to dimension.
    same with the if statements best to remove repeated syntax if possible but what ever is easier to read and debug or is your own style.

  3. #3
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,443
    Location
    Do dim them as long, the o/s will convert your integer to a long, do it's stuff, then convert back to integer for you, so it is totally wasteful. It may not impact too much, but as it is no harder to dim as long as integer, why wouldn't you?

    If question … your former example, without doubt. If tests take resources.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  4. #4
    VBAX Regular
    Joined
    Apr 2019
    Location
    London
    Posts
    25
    Location
    Thank you both for your replies. Kerry

Tags for this Thread

Posting Permissions

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