Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Byte or Integer?

Status
Not open for further replies.

lizray

Programmer
May 14, 2008
126
AU
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??
 
hOW ARE YA lizray . . .

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]

Calvin.gif
See Ya! . . . . . .

Be sure to see thread181-473997
Also faq181-2886
 
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.
 
Would boolean be of any use as its just a true / false flag?

Ian Mayor (UK)
Program Error
If people say I have bad breath, then why do they continue to ask me questions and expect me to answer them?
 
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.
 
Again . . . you'll never preceive the difference, [blue]even with large recordsets! . . .[/blue]

Calvin.gif
See Ya! . . . . . .

Be sure to see thread181-473997
Also faq181-2886
 
Thanks for your input. I am perhaps trying too hard and the solution is really only academic
 
lizray . . .

BTW: Welcome to [blue]Tek-Tips![/blue] [thumbsup2] 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] [thumbsup2]

Calvin.gif
See Ya! . . . . . .

Be sure to see thread181-473997
Also faq181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top