The main reason "Select Case" is faster is because it allows you to structure your code. As with an IF statement there's still a "compare" operation being preformed, but it's usually far better optimized.
The biggest problem with your original code is that every IF will be executed, which consequently wastes time.
Say for example that b1 = 245, the first IF is tested, the result returns true because b1 is within range of (255 - 243), so the block of code associated with that IF is executed, timerN is set to 1 etc ...
Now here's the problem -- all subsequent IFs are executed even though b1 is clearly out of range and the result will always return false while ever b = 245.
Select Case can be configured in a way so that only one comparison is ever performed, only one block of code is ever executed.Code:If (b1 <= 255 And b1 >= 243) Then ' Comparison always performed timerN = 1 timerAc = 600 timerBc = 180 End If If (b1 <= 242 And b1 >= 219) Then ' Comparison always performed timerN = 2 timerAc = 180 timerBc = 60 End If
Trent Jackson
Bookmarks