How do I pass parameters to a method both as normal and like a property?

178 views Asked by At

In RealBasic (now Xojo), which I'm leaving to the past, I used to be able to declare a method like this:

Sub MyCoolSub(param1 as string, Assigns parameter2 as integer)
Do
'Waste CPU time scrying the universe.
Loop
End Sub

And then call it in this way:

MyCoolSub("Answer")=42

Now I'd want to replicate this behaviour in VB.Net.

The closest thing I stumbled upon is the Property's clauses, but VS does not let me add parameters to it that would however require some overhead which decreases the convenience of this type of declaration.

Do you have any better suggestion?

PS. As a side question I would be pretty happy to know that there is a way to comment with "//" in VB.Net, as I'm not that comfortable with the apostrophe character. Is there any thing as a VS comment characters list? Maybe an extension could do it...

2

There are 2 answers

2
Bjørn-Roger Kringsjå On BEST ANSWER

When I look at the documentation for the Xojo Assigns keyword the closest thing I can think of is to create a write-only property like this:

Public WriteOnly Property theVolume(a As Integer, b As Integer) As Integer
    Set(c As Integer)
        Debug.WriteLine("a={0}, b={1}, c={2}", a, b, c)
    End Set
End Property

theVolume(1, 2) = 3

a=1, b=2, c=3

1
miroxlav On

Regarding your "P.S." note:

to ease your switching to VB.NET you can use the following AutoHotKey command:

:O://::'

This will do the appropriate substitution for you during typing. You can limit it only to your IDE window using #IfWinActive directive.

Anyway, Roslyn VB.Net compiler is now open source so you can download and play...