saboh12617
Board Regular
- Joined
- May 31, 2024
- Messages
- 67
- Office Version
- 365
- Platform
- Windows
Hello,
According to my research, what I'm trying to do is not possible, but I've noticed that many people here have a more advanced knowledge of VBA than I do, so I'm relying on you.
1. I know that unfortunately VBA is rather strange in terms of its OOP function, but on the subject of classes, can we redefine some basic operators for our objects? I'm thinking in particular of “=” or printing to String.
2. Otherwise, how do you deal with overloading in general, at the level of functions with identical names but taking different arguments? Is the only way to define the arguments as Variants and then check the TypeName?
Thanks for your advice.
Example
According to my research, what I'm trying to do is not possible, but I've noticed that many people here have a more advanced knowledge of VBA than I do, so I'm relying on you.
1. I know that unfortunately VBA is rather strange in terms of its OOP function, but on the subject of classes, can we redefine some basic operators for our objects? I'm thinking in particular of “=” or printing to String.
2. Otherwise, how do you deal with overloading in general, at the level of functions with identical names but taking different arguments? Is the only way to define the arguments as Variants and then check the TypeName?
Thanks for your advice.
Example
VBA Code:
Sub mySub()
Dim myClassInstance As New MyClass
Dim str As String
display myClassInstance
display str
End Sub
Function display(var As Variant)
Select Case TypeName(var)
Case “MyClass”
Debug.Print var.toStr
Case “String”
Debug.Print var
Case Else
'
End Select
End Function