1

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...

beppe9000
  • 1,056
  • 1
  • 13
  • 28
  • 1
    I don't know RealBasic or Xojo. Can you explain in words what it is that `MyCoolSub("Answer")=42` is supposed to do. To answer your second question, VB comments use a single apostrophe and not "//". – Blackwood Jan 25 '15 at 13:57
  • not often used, but `Rem` can be used to mark comments as well. Once Upon a Time it was short for `Remark` or use `'//` if you are looking to make it look familiar – Ňɏssa Pøngjǣrdenlarp Jan 25 '15 at 14:23
  • @Blackwood, the question is about how to get param1="Answer" and param2=42, while still calling the method as I showed. I consider this a really interesting feature of that language. – beppe9000 Jan 25 '15 at 14:58
  • The only thing I can think of that does that is the Set clause of a Property. See the answer posted by Bjørn-Roger Kringsjå. – Blackwood Jan 25 '15 at 15:11
  • I've seen it, I will probably mark it as THE answer, if nothing else pops in the near future. – beppe9000 Jan 25 '15 at 16:57

2 Answers2

5

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

Bjørn-Roger Kringsjå
  • 9,849
  • 6
  • 36
  • 64
2

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...

miroxlav
  • 11,796
  • 5
  • 58
  • 99