By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,149 Members | 885 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,149 IT Pros & Developers. It's quick & easy.

HOWTO: same function name, different return types

P: n/a
Hi, how can I do this (I don't really want to do this but what I do
want the same function name but have different return types and the
compiler keeps saying "public function .... they differ only by return
types")?

Public Function test() As Integer
Return 1
End Function

Public Function test() As Single
Return 1
End Function

Thank you
Peter
Nov 20 '05 #1
Share this Question
Share on Google+
10 Replies


P: n/a

Public Function test(x as Integer) As Integer
Return 1
End Function

Public Function test(x as Single) As Single
Return 1
End Function

Peter wrote:
Hi, how can I do this (I don't really want to do this but what I do
want the same function name but have different return types and the
compiler keeps saying "public function .... they differ only by return
types")?

Public Function test() As Integer
Return 1
End Function

Public Function test() As Single
Return 1
End Function

Thank you
Peter

Nov 20 '05 #2

P: n/a

Public Function test(x as Integer) As Integer
Return 1
End Function

Public Function test(x as Single) As Single
Return 1
End Function

Peter wrote:
Hi, how can I do this (I don't really want to do this but what I do
want the same function name but have different return types and the
compiler keeps saying "public function .... they differ only by return
types")?

Public Function test() As Integer
Return 1
End Function

Public Function test() As Single
Return 1
End Function

Thank you
Peter

Nov 20 '05 #3

P: n/a
Thanks but my functions don't accept any arguments,ie public function test()
as ....


"yEaH rIgHt" <no******@haha.com> wrote in message
news:10*************@corp.supernews.com...

Public Function test(x as Integer) As Integer
Return 1
End Function

Public Function test(x as Single) As Single
Return 1
End Function

Peter wrote:
Hi, how can I do this (I don't really want to do this but what I do
want the same function name but have different return types and the
compiler keeps saying "public function .... they differ only by return
types")?

Public Function test() As Integer
Return 1
End Function

Public Function test() As Single
Return 1
End Function

Thank you
Peter

Nov 20 '05 #4

P: n/a
Thanks but my functions don't accept any arguments,ie public function test()
as ....


"yEaH rIgHt" <no******@haha.com> wrote in message
news:10*************@corp.supernews.com...

Public Function test(x as Integer) As Integer
Return 1
End Function

Public Function test(x as Single) As Single
Return 1
End Function

Peter wrote:
Hi, how can I do this (I don't really want to do this but what I do
want the same function name but have different return types and the
compiler keeps saying "public function .... they differ only by return
types")?

Public Function test() As Integer
Return 1
End Function

Public Function test() As Single
Return 1
End Function

Thank you
Peter

Nov 20 '05 #5

P: n/a

Just because you have arguments doesn't mean you have to use them in
your function.

Or you can try this:

Public Function test() As Object
Return 1
End Function

Now you can return anything.

Peter Ignarson wrote:
Thanks but my functions don't accept any arguments,ie public function test()
as ....


"yEaH rIgHt" <no******@haha.com> wrote in message
news:10*************@corp.supernews.com...


Public Function test(x as Integer) As Integer
Return 1
End Function

Public Function test(x as Single) As Single
Return 1
End Function

Peter wrote:
Hi, how can I do this (I don't really want to do this but what I do
want the same function name but have different return types and the
compiler keeps saying "public function .... they differ only by return
types")?

Public Function test() As Integer
Return 1
End Function

Public Function test() As Single
Return 1
End Function

Thank you
Peter


Nov 20 '05 #6

P: n/a

Just because you have arguments doesn't mean you have to use them in
your function.

Or you can try this:

Public Function test() As Object
Return 1
End Function

Now you can return anything.

Peter Ignarson wrote:
Thanks but my functions don't accept any arguments,ie public function test()
as ....


"yEaH rIgHt" <no******@haha.com> wrote in message
news:10*************@corp.supernews.com...


Public Function test(x as Integer) As Integer
Return 1
End Function

Public Function test(x as Single) As Single
Return 1
End Function

Peter wrote:
Hi, how can I do this (I don't really want to do this but what I do
want the same function name but have different return types and the
compiler keeps saying "public function .... they differ only by return
types")?

Public Function test() As Integer
Return 1
End Function

Public Function test() As Single
Return 1
End Function

Thank you
Peter


Nov 20 '05 #7

P: n/a
Hi Peter

The simple answer is you can't. One reason is ... suppose you call test()
but don't assign its return value to anything. Which version of your test
function should the compiler call?

Try this instead

Public Sub test(ByRef Value As Integer)
Value = 1
End Sub

Public Sub test(ByRef Value As Single)
Value = 1
End Sub

HTH

Charles
"Peter" <pi*******@hotmail.com> wrote in message
news:a6*************************@posting.google.co m...
Hi, how can I do this (I don't really want to do this but what I do
want the same function name but have different return types and the
compiler keeps saying "public function .... they differ only by return
types")?

Public Function test() As Integer
Return 1
End Function

Public Function test() As Single
Return 1
End Function

Thank you
Peter

Nov 20 '05 #8

P: n/a
Hi Peter

The simple answer is you can't. One reason is ... suppose you call test()
but don't assign its return value to anything. Which version of your test
function should the compiler call?

Try this instead

Public Sub test(ByRef Value As Integer)
Value = 1
End Sub

Public Sub test(ByRef Value As Single)
Value = 1
End Sub

HTH

Charles
"Peter" <pi*******@hotmail.com> wrote in message
news:a6*************************@posting.google.co m...
Hi, how can I do this (I don't really want to do this but what I do
want the same function name but have different return types and the
compiler keeps saying "public function .... they differ only by return
types")?

Public Function test() As Integer
Return 1
End Function

Public Function test() As Single
Return 1
End Function

Thank you
Peter

Nov 20 '05 #9

P: n/a
Thanks for the replies everyone.
Peter

"Peter" <pi*******@hotmail.com> wrote in message
news:a6*************************@posting.google.co m...
Hi, how can I do this (I don't really want to do this but what I do
want the same function name but have different return types and the
compiler keeps saying "public function .... they differ only by return
types")?

Public Function test() As Integer
Return 1
End Function

Public Function test() As Single
Return 1
End Function

Thank you
Peter

Nov 20 '05 #10

P: n/a
Thanks for the replies everyone.
Peter

"Peter" <pi*******@hotmail.com> wrote in message
news:a6*************************@posting.google.co m...
Hi, how can I do this (I don't really want to do this but what I do
want the same function name but have different return types and the
compiler keeps saying "public function .... they differ only by return
types")?

Public Function test() As Integer
Return 1
End Function

Public Function test() As Single
Return 1
End Function

Thank you
Peter

Nov 20 '05 #11

This discussion thread is closed

Replies have been disabled for this discussion.