Search code examples
vbainterfaceimplements

Why are arguments renamed to RHS when implementing an Interface in VBA?


When you implement an Interface in your Class the arguments are automatically named RHS as shown on MDSN https://msdn.microsoft.com/en-us/library/office/gg264387.aspx

For example, if I create IInterface as so:

Public Property Let Value1(strValue1 As String)

End Property

Public Property Let Value2(strValue2 As String)

End Property

And implement it, the class would look like this:

Implements IInterface

Private Property Let IInterface_Value1(RHS As String)

End Property

Private Property Let IInterface_Value2(RHS As String)

End Property

It's a best practice to name your arguments in such a way as to provide some level of abstraction and make it easier to read and write code. I can actually change the arguments to whatever I want in the class after I've implemented the statements, as shown below, but my question is why does this happen? Is RHS a leftover from another language or is there a particular reason it's named like this?

Implements IInterface

Private Property Let IInterface_Value1(strValue1 As String)

End Property

Private Property Let IInterface_Value2(strValue2 As String)

End Property

The above compiles fine if I manually change it.


Solution

  • rhs stands for right hand side of operator = and lhs for left hand side of =. Why is this named like this here? Maybe its something which comes from c++ conventions. By the properties you have consider this code:

    Dim test As IInterface
    Set test = New ClassTest
    test.Value1 = "rhsVal"
    

    The new string value is actually on the right side of the = so therefor rhs.