locked
Cant overload each other because they differ only by optional parameters RRS feed

  • Question

  • User-1600012733 posted

    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)

    Tuesday, December 4, 2012 1:22 PM

Answers

  • User-1600012733 posted

    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.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, December 5, 2012 9:04 AM

All replies

  • User397347636 posted

    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.

    Tuesday, December 4, 2012 3:57 PM
  • User-1600012733 posted

    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?

    Tuesday, December 4, 2012 4:17 PM
  • User397347636 posted

    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?

    Tuesday, December 4, 2012 5:36 PM
  • User-1600012733 posted

    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.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, December 5, 2012 9:04 AM