Inc() and Dec() functions

Actually, this is easy to do in Xojo with exactly the syntax you’re looking for.

1 Like

I hope you have gotten your answer too.

Here, you’re doing the work twice. Using byref, there’s no need to also return the value.

In other words, you can simplify to two versions with your code above.

Version 1 (using a function):

Function INC(value as integer) As Integer
  return value+1
End Function

Called like this:
Value=INC(value)
(note: in this version, the value isn’t passed as ByRef, so it’s not modifiable from inside the function, hence why I’m straight returning value+1 instead of having the “value=value+1” step)

Version 2 (using ByRef):

Sub INC(byref value as integer)
  value=value+1
End Sub

Called like this:
INC(value)

The main difference, and is the purpose of ByRef, is that in version 2, you can modify “value” directly, without needing to return anything. The variable is modified “in place”.
As it looks obvious, version 2 is cleaner.

1 Like

Yes, because he is setting 2 separate variables at the same time.

Yes I have it sorted out. What I was doing is assigning the value to a pi-dog dataview cell. Ex. cell = Inc(RowNo). Now I am just calling Inc(RowNo) the using cell = RowNo. Thanks.

you can define both, with return if you need the result assigned to something else than the origin otherwise without return if you need only to increment (or whatever)

Indeed, but both ways in the same method is rarely useful.