[AccessD] Input and return data type in VB

Asger Blond ab-mi at post3.tele.dk
Thu Sep 16 17:47:35 CDT 2010


Hi list,
Just noticed a VB issue I haven't encountered before.
Say I want a function to receive two input parameters of type Byte and return a value of type Integer. I create a function like this:

Function SumNumbers(Number1 As Byte, Number2 As Byte) As Integer
   SumNumbers=Number1 + Number2
End Function

When testing the function I get this:
?SumNumbers(200,55) -> 255 (OK)
?SumNumbers(255,1) -> Run-time error 6 Overflow (??!!)

The last error isn't expected since the return type is declared as Integer.
I can prevent this behaviour by altering the function like this:
Function SumNumbers(Number1 As Integer, Number2 As Byte) As Integer
   SumNumbers=Number1 + Number2
End Function

In other words: I have to make room for the return type by declaring a sufficient large type for one or more of the input parameters.
This certainly looks like a bug to me. And the "solution" of course doesn't apply if I actually want to restrict the input parameters to Byte and make room for a return value exceeding Byte.
The same issue goes for other types, e.g. Integer as input type and Long as return type.
Any solution?
Asger





More information about the AccessD mailing list