[quote=205845:@Gerard Van Zee]Guys, thanks for your concern and help. But I’m still not completely convinced. I accept that the Operator_Convert method is a type conversion operation, that creates a new blank class instance. That does make it a bit of an outsider in the set of Operator overloading methods, though. Imho there is an Operator overloading procedure missing that would do what I need and make the set complete. This procedure would perhaps be called ‘Operator_Assign’ or something like that.
Class Class1
Dim X as Integer
Dim ID as Integer
Sub Operator_Assign(iVal as Integer)
Self.X= iVal
End Sub
End Class
Dim C as new Class1
C = 2
C = 2 would read “Assign a value 2 to C” and would not make a new instance of Class1, but simply assign the value 2 to the X property of the instance, as dictated by the override. In fact, there might be an ‘Operator_Retrieve’ method as well, that does the reverse of my Operator_Assign proposal, resulting into
dim y as integer = C
renders y equal to 2 with an ‘Operator_Retrieve’ overload in the above. Then there are overides for all operators: +, -, *, /, \, ^, mod, negate, including the = assignment.
Anyway, I realize that I’m pushing it too far now. I will try to find another way, or accept being bound to use the expression C.X = 2 .
Thx.[/quote]
You’ve described operator convert And because it does create an instance you could write
[code]Class Class1
Dim X as Integer
Dim ID as Integer
Sub Operator_Convert(iVal as Integer)
Self.X= iVal
End Sub
End Class
Dim C as Class1 = 2
C.ID = 1
MsgBox( "C.X = " + str(C.X) + ", C.ID = " + str(C.ID) )[/code]
in the code you have
The only issue I see is that you expect it to not create an instance but knowing that it does you can still make use of it