ByRef ???

Ricky D

Well-Known Member
Licensed User
Longtime User
When declaring a sub can we do something like


B4X:
Sub SetFareCount(ByRef l1 as Label, ByRef l2 as Label)
'get some data from db
Dim cur As Cursor
cur = mySQL.ExecQuery("Select SomeField,CustomerID FROM Cust")

If cur.RowCount>0 Then
    cur.Position=0 '1st record
    l1.Text = cur.getString("SomeField")
    l2.Text = cur.getInt("CustomerID")
End Sub

This would reside in my u Code module
Somehwhere else I'd do something like

B4X:
u.SetFareCount(lFirstLine,lSecondLine)

where they are local labels in an activity

I guess if not I'd have to do something like

B4X:
Type typeRecCount(Line1 As String, Line2 As String)
Dim myRecCount as typeRecCount
myRecCount = u.SetFareCount(DateTime.Now)
lRecCount1.Text = myRecCount.Line1
lrecCount2.Text = myrecCount.Line2
.
.
.
Sub SetFareCount(datein as Long) As myRecCount 'in u module
    Dim ret as typeRecCount
    typeRecCount.Initialize
    'get stuff from db

     ret.Line1 = cur.GetString("FareType")
     ret.Line2 = cur.GetString("FareCount")

     Return ret
End Sub

Does anyone know about using ByRef or something similar?

regards, Ricky
 

stevel05

Expert
Licensed User
Longtime User
Have you tried your code without the byref statements?
 
Upvote 0

Ricky D

Well-Known Member
Licensed User
Longtime User
thanks

I sure did and it worked like a charm.

B4X:
Sub SetFareCount(L1 As Label, L2 As Label)
    'get some stuff from db

    L1.Text = "Something from the db - Line 1"
    L2.Text = "Another from db - Line 2"
End Sub
.
.
.
u.SetFareCount(lRecCount, lRecCount2)

The 2 labels on the activity show the results just fine

That's easy!

regards, Ricky
 
Upvote 0
Top