Android Question Referencing non standard objects possible?

Levit

Member
Licensed User
Longtime User
Hi guys.
I am making an app with 16 grids (xngrid from xnobjects lib). So far so good.
Now I want to make 1 search routine where I can search in any grid just referencing
the grid. My attempt:
B4X:
sub Globals
   dim Grx, grid1, grid2, grid3, ......grid15 as xnGrid
end sub
'
Sub FindIngrid(what As String, grad As Object, col As Int) As Int
   Grx=grad    
   
   Dim rt=-1  As Int
   For rw=0 To Grx.RowCount-1
     If Grx.GetValue(rw, col)=what Then
       rt=rw
       Exit       
     End If
   Next   
   Return rt   ' return the found row
End Sub

This is far from work because Grx is not initialized. how can i make a routine
to call like: FindInGrid("Rose", Grid13, 3) ?
Or I have to write 16 searching routines, one for each grid ?
Any advice apreciated.
 

DonManfred

Expert
Licensed User
Longtime User
I suggest to Change grad as Object to grad as xngrid in your Sub Signature
 
Upvote 0

Levit

Member
Licensed User
Longtime User
Thank you @DonManfred , you saved my day.
By the way..... Very good work you have done in B4X. THANK YOU!!!!


I leave the full working routine here in the hope it may help somebody else.

B4X:
Sub FindIngrid(what As String, grad As xnGrid, col As Int) As Int
   Grx=grad   
   If col>Grx.ColCount-1 Then Return -1
  
  
   Dim rt=-1  As Int
   For rw=0 To Grx.RowCount-1
     If Grx.GetValue(rw, col)=what Then
       rt=rw
       Exit      
     End If
   Next  
   Return rt   ' return row
End Sub
 
Last edited:
Upvote 0
Top