Trouble with passing array to sub

enonod

Well-Known Member
Licensed User
Longtime User
I have the following code which works OK if the key(5,10) array is declared global and the MakeKeys sub has therefore no parameter.
I now declared the array in the sub and passed it in the call to MakeKeys.
I get an error saying that 'Text' is an unknown member (in the marked line).
I cannot see what is wrong, can somebody help please?
B4X:
Sub Keyboard
Dim line=1, i,j As Byte
Dim key(5,10) As Label
Dim kKeywh=1.6*kCellwh+line As Byte
Dim gCD As ColorDrawable
   gCD.Initialize(Colors.white,5)
   pKbd.Initialize("kbd")
   pnl.AddView(pKbd,0,pnl.Height/2,pnl.Width,4*(kKeywh+line)+line)
   pKbd.Color=Colors.black
   For i=0 To 3
      For j=0 To 9
         key(i,j).Initialize("key")
         key(i,j).Background=gCD
         key(i,j).Gravity=Gravity.CENTER
         key(i,j).Color=Colors.lightgray
         key(i,j).TextColor=Colors.black
         key(i,j).TextSize=22
         key(i,j).Text=""
         pKbd.AddView(key(i,j),j*(kKeywh+line)+line,i*(kKeywh+line)+line,kKeywh,kKeywh)
      Next
   Next
   MakeKeys(key)
   key(2,9).TextColor=Colors.magenta
   key(3,0).TextSize=18
   key(3,0).TextColor=Colors.magenta
'   key(3,0).Text="Shift"
   key(3,9).RemoveView
   key(3,8).Width=2*1.6*kCellwh+1
   key(3,8).TextColor=Colors.magenta
'   key(3,8).Text="Enter"
   pKbd.Visible=False
End Sub

Sub MakeKeys(key(,) As String)
Dim chars,charsC,tmpS As String
   chars="1234567890qwertyuiopasdfghjkl← zxcvbnm  "
   charsC="1234567890QWERTYUIOPASDFGHJKL← ZXCVBNM  "
Dim i,j As Byte
   If bShift Then tmpS=charsC Else tmpS=chars
    For i=0 To 3
      For j=0 To 9
         key(i,j).Text=tmpS.charat(j+i*10)   '***Error line
      Next
   Next
   key(3,0).Text="Shift"
   key(3,8).Text="Enter"
End Sub
 

enonod

Well-Known Member
Licensed User
Longtime User
Thank you stevel05, I seem to have had a blind spot, one of many.
 
Upvote 0
Top