[Gambas-user] ByRef
gambas at ...1938...
gambas at ...1938...
Tue Sep 2 16:14:04 CEST 2008
Am Dienstag, 2. September 2008 12:06:09 schrieb Emil Tchekov:
> Forgot to gave you example (VB)
>
>
> sub main()
>
> dim a as integer
>
> a=1
>
> debug.print a, pr1(a)
> debug.print a, pr2(a)
> debug.print a
>
> end sub
>
>
> private sub pr1(byval a)
>
> a=2
>
> return a
>
> end sub
>
>
> private sub pr2(byref a)
>
> a=2
>
> return a
>
> end sub
>
>
> result will be as follows
>
> 1 2
>
> 1* 2
>
> 2 (!)
>
>
> *As you can see on the first sub the var a is local to your sub, it was
> changed (returns 2), but the passed a has stil value 1
>
> (!) in the second procedure the passed var a was changed! (the a that was
> defined in the sub main!)
Hi Emil,
thanks for your reply! ...it helped to understand the concepts and the syntax.
Meanwhile I got it running. Gambas wants the "Byref" twice! Once by calling
the procedure and a second time in the header of the function.
Sub Main
DIM sResult as String
sResult = ""
GetData(Byref sResult)
Print sResult & "\n"
End
Public Sub GetData(ByRef sResult As String)
sResult = "Hello"
End
Greetz
Stevie
More information about the User
mailing list