#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 30
Default 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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default 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


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,202
Default 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

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default 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

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default 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


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel 2002 : Convert Positive Numbers to Negative Numbers ? Mr. Low Excel Discussion (Misc queries) 2 November 6th 06 03:30 PM
Need to reconcile numbers accounting Harlan Grove code doesn't work for negative numbers [email protected] Excel Programming 1 July 28th 06 07:09 AM
Help! How do you get excel to find the x(changes daily, marked in a cell from another formula) highest numbers in a group of numbers and sum them up? C-Man23 Excel Worksheet Functions 3 January 19th 06 09:52 AM
Help! How do you get excel to find the x(changes daily, marked in a cell from another formula) highest numbers in a group of numbers and sum them up? C-Man23 Excel Worksheet Functions 1 January 9th 06 01:23 PM


All times are GMT +1. The time now is 12:10 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"