Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Sub MyByte()
Dim b1 As Byte, b2 As Byte, i As Long For b1 = 1 To 200 For b2 = 1 To 200 i = b1 + b2 Next Next End Sub Thanks and regards. voda |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
When you process numbers which are entirely bytes the result (or partial
result) will be made as a byte. However if the result is outside the scope of a byte (0-255) you will get an overflow error. Here's one way to correct your example i = CLng(b1) + b2 The following fails because 32000 and 1000 as initially interpreted as Integers, but 33000 is more than the scope of an Integer dim i as long i = 32000 + 1000 ' overflow i = 32000& + 1000 ' works Regards, Peter T "voda" wrote in message ... Sub MyByte() Dim b1 As Byte, b2 As Byte, i As Long For b1 = 1 To 200 For b2 = 1 To 200 i = b1 + b2 Next Next End Sub Thanks and regards. voda |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Bytes can range from 0 to 255.
In: i = b1 + b2 The arithmetic (the righthand side) is done in byte arithmetic. So it blows up at 256 (b1=56 and b2=200). If I were you, I'd never use "As Byte" or "As Integer". I'd always use as "As Long". voda wrote: Sub MyByte() Dim b1 As Byte, b2 As Byte, i As Long For b1 = 1 To 200 For b2 = 1 To 200 i = b1 + b2 Next Next End Sub Thanks and regards. voda -- Dave Peterson |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() "voda" wrote: Sub MyByte() Dim b1 As Byte, b2 As Byte, i As Long For b1 = 1 To 200 For b2 = 1 To 200 i = b1 + b2 Next Next End Sub Thanks and regards. voda |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
OnTime code error "can't execute code in break mode" | Excel Programming | |||
Make "Edit" mode default, rather than "Enter"? | Excel Discussion (Misc queries) | |||
If changed array formula reduce ""\""\""\ - signs to #Missing, will it make ... | Excel Programming | |||
What is Error "Method "Paste" of object "_Worksheet" failed? | Excel Programming | |||
how can I make an excel cell "mark" or "unmark" when clicked on? | Excel Discussion (Misc queries) |