[AccessD] Input and return data type in VB

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


Thanks Stuart - exactly what I was looking for!
Asger

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

Explicit conversion of datatypes:

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

-- 
Stuart

On 17 Sep 2010 at 0:47, Asger Blond 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