what's wrong with the following. I am getting "Cant overload each other because they differ only by optional parameters" error.
If I remove "Optional ByVal UI As Boolean = False" it works fine.
Really appreciate your help
Public Function Test(ByVal ConnectionString As String, _
ByVal Timeout As Integer, _
ByVal SQLstring As String, _
Optional ByVal UI As Boolean = False)
Public Function Test(ByVal ConnectionString As String, _
ByVal Timeout As Integer, _
ByVal SQLString As String, _
ByVal ID As Boolean, _
Optional ByVal UI As Boolean = False)
How is VB going to determine which function should be called if you provide 4 arguments?
With 3 arguments or 5 arguments, the exact function being called can be determined - with 4 arguments, VB (or you or I) cannot figure out which function you want to call.
Thanks for taking time to answer. ID boolean (4th parameter in second function) which seperates two functions.
First function having 4 parameters
Public Function Test(ByVal ConnectionString As String, ByVal Timeout As Integer, ByVal SQLstring As String, Optional ByVal UI As Boolean = False)
Second function having 5 parameters
Public Function Test(ByVal ConnectionString As String, ByVal Timeout As Integer, ByVal SQLString As String,
ByVal ID As Boolean, Optional ByVal UI As Boolean = False)
A call to "Test" using 4 arguments could be a call to either function - the first with an argument for each parameter or the second with an argument for each non-optional parameter. How would anyone or the compiler know what you intended?
SACSSP
Member
1 Points
16 Posts
Cant overload each other because they differ only by optional parameters
Dec 04, 2012 05:22 PM|LINK
Hi,
what's wrong with the following. I am getting "Cant overload each other because they differ only by optional parameters" error.
If I remove "Optional ByVal UI As Boolean = False" it works fine.
Really appreciate your help
Public Function Test(ByVal ConnectionString As String, _
ByVal Timeout As Integer, _
ByVal SQLstring As String, _
Optional ByVal UI As Boolean = False)
Public Function Test(ByVal ConnectionString As String, _
ByVal Timeout As Integer, _
ByVal SQLString As String, _
ByVal ID As Boolean, _
Optional ByVal UI As Boolean = False)
David Anton
Contributor
3702 Points
637 Posts
Re: Cant overload each other because they differ only by optional parameters
Dec 04, 2012 07:57 PM|LINK
How is VB going to determine which function should be called if you provide 4 arguments?
With 3 arguments or 5 arguments, the exact function being called can be determined - with 4 arguments, VB (or you or I) cannot figure out which function you want to call.
http://www.tangiblesoftwaresolutions.com
Instant C# - VB to C# Converter
Instant VB - C# to VB Converter
SACSSP
Member
1 Points
16 Posts
Re: Cant overload each other because they differ only by optional parameters
Dec 04, 2012 08:17 PM|LINK
Hi David,
Thanks for taking time to answer. ID boolean (4th parameter in second function) which seperates two functions.
First function having 4 parameters
Public Function Test(ByVal ConnectionString As String, ByVal Timeout As Integer, ByVal SQLstring As String, Optional ByVal UI As Boolean = False)
Second function having 5 parameters
Public Function Test(ByVal ConnectionString As String, ByVal Timeout As Integer, ByVal SQLString As String, ByVal ID As Boolean, Optional ByVal UI As Boolean = False)
Am I missing something?
David Anton
Contributor
3702 Points
637 Posts
Re: Cant overload each other because they differ only by optional parameters
Dec 04, 2012 09:36 PM|LINK
A call to "Test" using 4 arguments could be a call to either function - the first with an argument for each parameter or the second with an argument for each non-optional parameter. How would anyone or the compiler know what you intended?
http://www.tangiblesoftwaresolutions.com
Instant C# - VB to C# Converter
Instant VB - C# to VB Converter
SACSSP
Member
1 Points
16 Posts
Re: Cant overload each other because they differ only by optional parameters
Dec 05, 2012 01:04 PM|LINK
David,
I fixed it. I changed the last variable to Int and it worked. My guess is because of last 2 variables boolean it did not accepted it.
Thanks for your time David.