PDA

View Full Version : [SOLVED] Coding Efficiency (2)



Kerry H
04-20-2019, 10:15 PM
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.

pike
04-20-2019, 11:41 PM
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.

xld
04-21-2019, 04:20 AM
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.

Kerry H
04-21-2019, 01:46 PM
Thank you both for your replies. Kerry