create a subroutine


I have a question about creating a subroutine, which means it doesn’t have any return value. Like a subroutin just write certain data into serial port or clear serval gloable properties to their inital value, etc.

What’s the best way to do that? I use methods a lot, but that require a return value. in the VB, I can use something like,

Sub doSomething(ByVal i as Integer, ByRef j as Single) ' blocks of code End sub

Then, call it in an event or anywhere I want,

Dim num as single doSomething (5, num)

What’s the similar methods in Xojo?


In Xojo Methods don’t return a value, and Functions return a value.
Your code block would work just fine.

Have you read the manual yet? Lots of useful stuff in there.

Just leave the return value blank in the inspector. In fact, you can select an item (window/class/module) in the Xojo navigator (make sure it is blue not gray) and paste your sub dosomething etc… and a new method will be inserted.

Leave the Return type blank.

See Methods in the User Guide.


FWIW in the spirit of examples if you do happen to create a function (method that returns a value) and say you wanted to call if bypassing the return value you can do:

Call myFunction()

instead of:

Dim returnValue as String = myFunction()