[Gambas-user] Function Parameter Out ?
Fabien Bodard
gambas.fr at gmail.com
Sat Aug 4 08:12:49 CEST 2018
Well there is also the tricks of passing an array
If you modify a value in an object... you modify the object not the ref...
so it's an indirect byref argument
Le ven. 3 août 2018 19:40, ML <d4t4full at gmail.com> a écrit :
> *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.
>
> ----[ Gambas mailing-list is hosted by https://www.hostsharing.net ]----
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.gambas-basic.org/pipermail/user/attachments/20180804/1ea8366c/attachment.html>
More information about the User
mailing list