469,934 Members | 1,847 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,934 developers. It's quick & easy.

Overload Resolution error

Hi,

I have 2 overloaded functions as below:

myfunc(byval val as Decimal) as string
myfunc(byval val as String) as string

When calling the function with a single like:

dim num1 as single = ...

myfunc(num1)

I get an compiler error saying:
------------------------------------------
error BC30519: Overload resolution failed because no accessible "myfunc" can
be called without a narrowing conversion:

'Public Shared Overloads Function myfunc(val As Decimal) As String':
Argument matching parameter 'val' narrows from 'Double' to 'Decimal'.

'Public Shared Overloads Function myfunc(val As String) As String': Argument
matching parameter 'val' narrows from 'Double' to 'String'.

------------------------------------------

What I don't understand is, should it be widening from Double to Decimal?
Why is the compiler trying to do

narrowing from Double to Decimal?

Thanks!



Nov 19 '05 #1
5 7671
A single is not a decimal, change one of them to match the other

Tom--
==========================================
= Tom Vande Stouwe MCSD.net, MCAD.net, MCP
= 45Wallstreet.com (www.45wallstreet.com)
= (803)-345-5001
==========================================
= If you are not making any mistakes
..= ..you are not trying hard enough.
==========================================
"Gang Zhang" <gz****@weightwatchers.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
Hi,

I have 2 overloaded functions as below:

myfunc(byval val as Decimal) as string
myfunc(byval val as String) as string

When calling the function with a single like:

dim num1 as single = ...

myfunc(num1)

I get an compiler error saying:
------------------------------------------
error BC30519: Overload resolution failed because no accessible "myfunc" can be called without a narrowing conversion:

'Public Shared Overloads Function myfunc(val As Decimal) As String':
Argument matching parameter 'val' narrows from 'Double' to 'Decimal'.

'Public Shared Overloads Function myfunc(val As String) As String': Argument matching parameter 'val' narrows from 'Double' to 'String'.

------------------------------------------

What I don't understand is, should it be widening from Double to Decimal?
Why is the compiler trying to do

narrowing from Double to Decimal?

Thanks!



Nov 19 '05 #2
"Gang Zhang" <gz****@weightwatchers.com> schrieb
Hi,

I have 2 overloaded functions as below:

myfunc(byval val as Decimal) as string
myfunc(byval val as String) as string

When calling the function with a single like:

dim num1 as single = ...

myfunc(num1)

I get an compiler error saying:
------------------------------------------
error BC30519: Overload resolution failed because no accessible
"myfunc" can be called without a narrowing conversion:

'Public Shared Overloads Function myfunc(val As Decimal) As
String': Argument matching parameter 'val' narrows from 'Double' to
'Decimal'.

'Public Shared Overloads Function myfunc(val As String) As String':
Argument matching parameter 'val' narrows from 'Double' to
'String'.

------------------------------------------

What I don't understand is, should it be widening from Double to
Decimal? Why is the compiler trying to do

narrowing from Double to Decimal?


Enable Option Strict and you'll get the "real" error message.

Without Option Strict: I get a different message: "...narrwos from 'SINGLE'
to Decimal". Where does your "double" come from? Nevertheless, I don't see
the point: None of the signatures fit. Conversion from Single to Decimal is
a narrowing, not a widening conversion. So, not even implicit conversion
can be done. Therefore the error. Pass CDec(num1) (which might lead to a
runtime error) or Num1.ToString.
--
Armin

Nov 19 '05 #3
..Net doesn't convert anything to another datatype automaticly like it would
in VB6, that's why Ctype was added..

"Gang Zhang" <gz****@weightwatchers.com> wrote in message
news:eA**************@TK2MSFTNGP09.phx.gbl...
Thanks for the reply.

I understand a Single type is different from a Decimal type. And
I could have added another overloaded function that takes a Single
type input.

However, the question remains that the VB.NET compiler
should have done the automatical widening of Single(4 bytes) to a
Decimal( 16 bytes) and used the existing function instead of giving
a compiler error on attempting to do narrowing.
Gang

"Tom Vande Stouwe MCSD.net" <to**@conpro.net> wrote in message
news:#3**************@TK2MSFTNGP09.phx.gbl...
A single is not a decimal, change one of them to match the other

Tom--
==========================================
= Tom Vande Stouwe MCSD.net, MCAD.net, MCP
= 45Wallstreet.com (www.45wallstreet.com)
= (803)-345-5001
==========================================
= If you are not making any mistakes
.= ..you are not trying hard enough.
==========================================
"Gang Zhang" <gz****@weightwatchers.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
Hi,

I have 2 overloaded functions as below:

myfunc(byval val as Decimal) as string
myfunc(byval val as String) as string

When calling the function with a single like:

dim num1 as single = ...

myfunc(num1)

I get an compiler error saying:
------------------------------------------
error BC30519: Overload resolution failed because no accessible
"myfunc"
can
be called without a narrowing conversion:

'Public Shared Overloads Function myfunc(val As Decimal) As String':
Argument matching parameter 'val' narrows from 'Double' to 'Decimal'.

'Public Shared Overloads Function myfunc(val As String) As String':

Argument
matching parameter 'val' narrows from 'Double' to 'String'.

------------------------------------------

What I don't understand is, should it be widening from Double to

Decimal? Why is the compiler trying to do

narrowing from Double to Decimal?

Thanks!





Nov 19 '05 #4
"Gang Zhang" <gz****@weightwatchers.com> schrieb
Thanks for the reply.

I understand a Single type is different from a Decimal type. And
I could have added another overloaded function that takes a Single
type input.

However, the question remains that the VB.NET compiler
should have done the automatical widening of Single(4 bytes) to a
Decimal( 16 bytes)
That's narrowing, not widening.

ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB/vbcn7/html/vaconWideNarrowConversi
ons.htm

(see hints in signature)

For example, the biggest positive value for Single is 3.4028235E+38
whereas it is only about 79E+28 for the Decimal data type.
and used the existing function instead of
giving a compiler error on attempting to do narrowing.


--
Armin

- Links might be split into two lines. Concatenate them using notepad.
- Links might require to add a ".nnnn" after the "2003FEB", e.g.
"2003FEB.1033" for localized versions.
- Links starting with "ms-help" are URLs for the document explorer (<F1>).
Paste them in the URL textbox and press enter. Using internal help (menu
tools -> options -> environment -> help), display the "Web" toolbar that
contains the textbox.

Nov 19 '05 #5
Thanks all for the help!

"Jay B. Harlow [MVP - Outlook]" <Ja********@email.msn.com> wrote in message
news:eh*************@TK2MSFTNGP10.phx.gbl...
Gang,
But Single to Decimal is a narrowing not a widening conversion!

It not based on number of bytes as Single has a wider range then Decimal!
Although Decimal does has more precision. Single to Decimal would loose the range, hence its not allowed. Decimal to Single would loose the precision,
so its rounded and allowed.

See the conversion section of the Visual Basic .NET Language Specification

http://msdn.microsoft.com/library/de...us/vbls7/html/
vblrfVBSpec10.asp
Specifically Narrowing Conversions:
http://msdn.microsoft.com/library/de...us/vbls7/html/
vblrfVBSpec10_4.asp
Very specifically Narrowing Numeric Conversions:
http://msdn.microsoft.com/library/de...us/vbls7/html/
vblrfVBSpec10_4_1.asp
Hope this helps
Jay

"Gang Zhang" <gz****@weightwatchers.com> wrote in message
news:eA**************@TK2MSFTNGP09.phx.gbl...
Thanks for the reply.

I understand a Single type is different from a Decimal type. And
I could have added another overloaded function that takes a Single
type input.

However, the question remains that the VB.NET compiler
should have done the automatical widening of Single(4 bytes) to a
Decimal( 16 bytes) and used the existing function instead of giving
a compiler error on attempting to do narrowing.
Gang

"Tom Vande Stouwe MCSD.net" <to**@conpro.net> wrote in message
news:#3**************@TK2MSFTNGP09.phx.gbl...
A single is not a decimal, change one of them to match the other

Tom--
==========================================
= Tom Vande Stouwe MCSD.net, MCAD.net, MCP
= 45Wallstreet.com (www.45wallstreet.com)
= (803)-345-5001
==========================================
= If you are not making any mistakes
.= ..you are not trying hard enough.
==========================================
"Gang Zhang" <gz****@weightwatchers.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
> Hi,
>
> I have 2 overloaded functions as below:
>
> myfunc(byval val as Decimal) as string
> myfunc(byval val as String) as string
>
> When calling the function with a single like:
>
> dim num1 as single = ...
>
> myfunc(num1)
>
> I get an compiler error saying:
> ------------------------------------------
> error BC30519: Overload resolution failed because no accessible "myfunc" can
> be called without a narrowing conversion:
>
>
>
> 'Public Shared Overloads Function myfunc(val As Decimal) As String':
> Argument matching parameter 'val' narrows from 'Double' to 'Decimal'. >
>
>
> 'Public Shared Overloads Function myfunc(val As String) As String':
Argument
> matching parameter 'val' narrows from 'Double' to 'String'.
>
> ------------------------------------------
>
>
>
> What I don't understand is, should it be widening from Double to

Decimal?
> Why is the compiler trying to do
>
> narrowing from Double to Decimal?
>
>
>
> Thanks!
>
>
>
>
>
>
>
>
>



Nov 19 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Arturo Cuebas | last post: by
13 posts views Thread by Vladimir Granitsky | last post: by
reply views Thread by Eph0nk | last post: by
2 posts views Thread by Michi Henning | last post: by
3 posts views Thread by Christof Nordiek | last post: by
1 post views Thread by =?Utf-8?B?QU1lcmNlcg==?= | last post: by
2 posts views Thread by xtrigger303 | last post: by
9 posts views Thread by sebastian | last post: by
5 posts views Thread by jknupp | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.