hello,
i m creating a calculator in 16 bit. how can i detect an overflow in run time?
ohad
Printable View
hello,
i m creating a calculator in 16 bit. how can i detect an overflow in run time?
ohad
one way is to use larger data type to store the result and check for overflow. for instance,
dim i as integer
dim j as integer
dim l as long
l = i + j
if l > 32767 then
'overflow
end
second way, use On Error Goto ....
[vbcode]
On Error Goto ErrorTrap
dim i as integer
dim j as integer
dim k as integer
k = i + j
exit function
ErrorTrap:
'if k overflow, this part of code will be executed ...
HTH
cksiow
http://vblib.virtualave.net - share our codes