0

I have overloaded a function 3 times.

I saw that VBA supports function overloading but i am unable to execute this without getting error.

Function nothingToZero(X As Integer) As Integer
    If X = "" Then
        nothingToZero = 0
    Else
        nothingToZero = X
    End If
End Function
    
Function nothingToZero(X As Single) As Integer
     If X = "" Then
         nothingToZero = 0
     Else
         nothingToZero = X
     End If
End Function
    
Function nothingToZero(X As String) As Integer
   If X = "" Then
       nothingToZero = 0
   Else
       nothingToZero = X
   End If
End Function
braX
  • 11,506
  • 5
  • 20
  • 33
  • 2
    What's your source? VBA does not support function overloading. – BigBen Jun 25 '20 at 14:33
  • https://stackoverflow.com/questions/64436/function-overloading-and-udf-in-excel-vba – BigBen Jun 25 '20 at 14:34
  • 2
    VBA isn't the same thing as VB.Net. Despite the similarity in syntax, the underlying semantics of the two languages are very different. – John Coleman Jun 25 '20 at 14:39
  • My source was googling "function overloading vba". I'll be using this workaround since there is no function overloading. – PEARL FUELS BPCL OUTLET Jun 25 '20 at 14:39
  • 1
    Microsoft in its wisdom has created an odd situation where two fairly different languages have a very similar name and furthermore a syntax which is so similar that it is easy to see code written in one language and mistake it for code written in the other. Google frequently calls up VB.Net solutions even when you use VBA in the search. – John Coleman Jun 25 '20 at 14:42
  • It was probably [this](https://learn.microsoft.com/en-us/dotnet/visual-basic/programming-guide/language-features/procedures/procedure-overloading) and Microsoft's docs don't make it very obvious if you're in the VB6, VBA or VB.Net sections. – Warcupine Jun 25 '20 at 14:46
  • 1
    Ints and singles will never be `""`. They default to zero. – Kostas K. Jun 25 '20 at 14:52
  • @Warcupine technically, it does say .NET in the top left set of links... maybe people just dont look at those? – braX Jun 25 '20 at 15:14
  • @braX Yeah, but it isn't as obvious as the (Visual Basic) at the top of the article. – Warcupine Jun 25 '20 at 15:16

0 Answers0