![]() |
def numbers
What is the best way to def integer counters? I don't understand vb's
definitions (Integer, long etc.). It used to be you used the def that used the least memory. Is that still true? for n = 1 to 100 what would you def n as for most efficiency and least memory use. Or isn't that a factor anymore? I am getting back into programming a little after 18 years. John |
def numbers
I would use Long. In this case you could use Byte, but then if maybe later
you go beyond the reach of Byte then you will get an overflow error. Long is more efficient than Integer, so I would do Dim n As Long. RBS "John" wrote in message ... What is the best way to def integer counters? I don't understand vb's definitions (Integer, long etc.). It used to be you used the def that used the least memory. Is that still true? for n = 1 to 100 what would you def n as for most efficiency and least memory use. Or isn't that a factor anymore? I am getting back into programming a little after 18 years. John |
def numbers
What is the best way to def integer counters? I don't understand vb's
definitions (Integer, long etc.). It used to be you used the def that used the least memory. Is that still true? for n = 1 to 100 what would you def n as for most efficiency and least memory use. Or isn't that a factor anymore? I am getting back into programming a little after 18 years. You are thinking of DefTYPE where TYPE is one of the data types (for example, DefInt, DefStr, etc.). The use of DefType's to identify ranges of letters that will automatically be declared as a certain data type went out of favor quite some time ago. Simple lists of Dim statements identifying each variable are the norm today. Just remember that in VB and VBA, while you can combine multiple variable in a single Dim statement, you must identify each variable's type individually. So, while in some languages you can do the equivalent of this... Dim A, B, C As Long in VB and VBA you ***MUST*** do it this way instead... Dim A As Long, B As Long, C As Long If you forget and do it like the first Dim statement, only C would be declared as a Long... A and B would be Variants (which take up more memory and are slower to work with). Most people seem to like to stick with one variable per Dim statement.... Dim A As Long Dim B As Long Dim C As Long sort of makes an easy to look up "dictionary" of your variables. Rick |
def numbers
Unless you are using a 64 bit operating system, the 32 bit registers line up
with Longs. Using Byte or Integer must be handled specially, so it is more efficient to use Longs. When you had only 16K of memory, it was more of a premimum than when you have more than 256 MB -- Regards, Tom Ogilvy "John" wrote: What is the best way to def integer counters? I don't understand vb's definitions (Integer, long etc.). It used to be you used the def that used the least memory. Is that still true? for n = 1 to 100 what would you def n as for most efficiency and least memory use. Or isn't that a factor anymore? I am getting back into programming a little after 18 years. John |
def numbers
John,
The difference between an Integer and a Long is the amount of memory allocated for each and the largest number that such a variable can contain. An Integer is 2 bytes in length and, assuming signed values, can contain a number between -32,768 to 32,767. A Long is 4 bytes and can contain a number between -2,147,483,648 to 2,147,483,647. If you attempt to exceed these bounds, you'll get an overflow error. Neither an Integer nor a Long may contain fractional numbers (e.g., 1.234). The Single and Double data types are used for fractional numbers and these types differ in the range of the values that may be stored and the number of digits of precision (e.g., how many decimal places) the number may contain. Look in VBA Help (not Excel Help) for "Data Type Summary" for more information about the various data types and their limitations. Generally speaking, you should use Longs for integral values even if the given number will fit within an Integer or even a Byte. This is due to the fact that the CPU works in 32-bit (4 byte) "chunks" and must do additional conversions for Integer values. -- Cordially, Chip Pearson Microsoft MVP - Excel Pearson Software Consulting www.cpearson.com (email on the web site) "John" wrote in message ... What is the best way to def integer counters? I don't understand vb's definitions (Integer, long etc.). It used to be you used the def that used the least memory. Is that still true? for n = 1 to 100 what would you def n as for most efficiency and least memory use. Or isn't that a factor anymore? I am getting back into programming a little after 18 years. John |
All times are GMT +1. The time now is 06:18 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com