[AccessD] Input and return data type in VB

Asger Blond ab-mi at post3.tele.dk
Fri Sep 17 09:08:23 CDT 2010


Well, converting the inputs is quite acceptable for me, so I'll stop blaming VB for a bug.
Thanks
Asger

-----Oprindelig meddelelse-----
Fra: accessd-bounces at databaseadvisors.com [mailto:accessd-bounces at databaseadvisors.com] På vegne af Charlotte Foust
Sendt: 17. september 2010 04:54
Til: Access Developers discussion and problem solving
Emne: Re: [AccessD] Input and return data type in VB

.Net works the same way, and we always used Stuart's approach there as
well.  Even though you were trying to return an integer, the overflow
occurred in dealing with bytes and you can't add bytes that come out
to more than the limit of the byte data type.  Not really a  but, just
the way it works.

Charlotte Foust

On Thu, Sep 16, 2010 at 3:47 PM, Asger Blond <ab-mi at post3.tele.dk> wrote:
> 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
>
>
> --
> AccessD mailing list
> AccessD at databaseadvisors.com
> http://databaseadvisors.com/mailman/listinfo/accessd
> Website: http://www.databaseadvisors.com
>

-- 
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com





More information about the AccessD mailing list