[Gambas-user] Function Parameter Out ?

ML d4t4full at gmail.com
Fri Aug 3 19:38:49 CEST 2018


*On 03/08/18 14:25, KKing wrote:*
> Can a Function update the content of the parameter values before
> returning and or have the concept of the "OUT" parameter?
> K.

Yes, altough you suuuure know it's "not a good programming practice",
right? (ahem)
To achieve it you should use the ByRef parameter access modifier, but
the tweak is that you should use in both, the call AND the sub/function
declaration:

    ' Gambas class file
   
    Public Sub Form_Open()
   
        Dim i As Integer = 10
   
        ChangeInputParameter(ByRef i)                                   
           'Note the BYREF modifier
   
        Message.Info("I = " & CStr(i))
   
    End
   
    Private Sub ChangeInputParameter(ByRef myVar As Integer)    'Note
the BYREF modifier
   
        myVar = myVar + 10
   
    End

Also: Try removing any one of the two ByRef keywords.

You can, of course, also use ByRef in Functions, not only in Subs. This
was just a Q&D (quick & dirty) example.
Don't know if it can be used in Properties, though...

zxMarce.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.gambas-basic.org/pipermail/user/attachments/20180803/e3f8eb42/attachment-0001.html>


More information about the User mailing list