(08-08-2022, 02:14 PM)Jack Wrote:(07-18-2022, 03:38 PM)mdijkens Wrote: The reason your initial code passes by value to the sub is the use of double bracketsI don't think that enclosing the argument in parenthesis forces the argument to be treated as by value,
Call MySub(a) ' passes reference to a
Call MySub((a)) ' evaluates (a) to tempvalue and passes reference to tempvalue
(Same is true for Functions btw)
Try it. It is really true!
Code: (Select All)
x = 3
subproc x
Print "passed byref:"; x ' prints 4
x = 3
subproc (x)
Print "passed byval:"; x ' prints 3
x = 3
Call subproc(x)
Print "passed byref:"; x ' prints 4
x = 3
Call subproc((x))
Print "passed byval:"; x ' prints 3
End
Sub subproc (a)
a = a + 1
End Sub
45y and 2M lines of MBASIC>BASICA>QBASIC>QBX>QB64 experience