ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Dim Array as Byte (https://www.excelbanter.com/excel-programming/429163-dim-array-byte.html)

ExcelMonkey

Dim Array as Byte
 
What would be the advantage to dimensioning an array as a Byte - such as:

Arr() As Byte

Thanks

EM

Chip Pearson

Dim Array as Byte
 
There isn't really any advantage unless it is required by the
procedure to which you are passing it. As a general coding practice,
it is best to use Longs or Doubles for numeric variables. Forget about
Integers and Singles. A typical computer today has memory to spare and
the savings gained by using Bytes, Integers, or Singles are miniscule.
If you are that concerned about memory usage, you shouldn't be using
VBA in the first place.


Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group, 1998 - 2009
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)

Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group, 1998 - 2009
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)


On Fri, 29 May 2009 13:01:01 -0700, ExcelMonkey
wrote:

What would be the advantage to dimensioning an array as a Byte - such as:

Arr() As Byte

Thanks

EM


r

Dim Array as Byte
 
Sub UseByteArr()
Dim arr() As Byte
Dim s As String
Dim l As Long
s = "test"
arr = s

For l = 0 To UBound(arr) Step LenB("A")
Debug.Print arr(l)
Debug.Print Chr(arr(l))
Next

End Sub

regards
r

http://excelvba.altervista.org/blog/...ternative.html


"ExcelMonkey" wrote:

What would be the advantage to dimensioning an array as a Byte - such as:

Arr() As Byte

Thanks

EM


Tim Zych

Dim Array as Byte
 
I agree with what Chip says, functionally it is not going to net much in
today's real world, unless maybe you have millions of elements in the array.
After all, you are not designing a game for the Atari 2600 and limited to <
4K of space.

One advantage I can think of, however, is that it is self-documenting, much
like a Boolean is.

--
Regards,
Tim Zych
http://www.higherdata.com
Workbook Compare - Excel data comparison utility

"ExcelMonkey" wrote in message
...
What would be the advantage to dimensioning an array as a Byte - such as:

Arr() As Byte

Thanks

EM




Charles Williams

Dim Array as Byte
 
The main advantage is more efficient processing of characters in strings.

Assigning a string to a byte array and then looping thru the byte array is
much more efficient than looping through the characters in the string using
MID.

regards
Charles Williams
Decision Models

"ExcelMonkey" wrote in message
...
What would be the advantage to dimensioning an array as a Byte - such as:

Arr() As Byte

Thanks

EM





All times are GMT +1. The time now is 05:57 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com