I need to test a flag while in a loop, Can anyone familiar with VBA internals, tell me it is quicker if the flagtype is BYTE or INTEGER or anything else??
Wether Byte(8 bits) or Integer(16 bits) or Long(32 bits), you'll never preceive the difference, even with large recordsets. [blue]The type you use, is dependent on the numerical limit of what your dealin with![/blue]
ThaAceMan1 is right ... the difference will probably be unmeasurable.
In theory a Long is probably faster because it occupies a full 32-bit word so the compiler doesn't need to generate code to deal with part of a word as it would for Integer, Byte or Bit fields. With most computers processing billions of instructions per second, those few extra instructions are processed in less time than even very high-precision timers can measure.
Boolean is a possibilty. I had heard that VBA converts data types to LONG before testing in an IF statement. If this is so, then it would be faster if the Data types were already long. The purpose of the question is to find out what data type makes for a faster comparison in an if statement.
Just to repeat, Long is probably faster because there is no need to generate code to handle partial words.
To also repeat however ... it probably doesn't matter in the sense that there will likely be no measurable difference in the speed. You are best advised to use the data type that makes your code easiest to understand and maintain. There is no benefit in trying to out-smart an optimizing compiler.
BTW: Welcome to [blue]Tek-Tips![/blue] Do have a look at one of the links at the bottom of my post. The links will help you [blue]ask better questions[/blue], get [blue]quick responses[/blue], [blue]better answers[/blue], and gives insite into [blue]etiquette[/blue] here in the forums. Again . . . Welcome to [blue]Tek-Tips![/blue]
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.