Android Question Add Label Date Headings To Program Created Panel Problem

Big Dave

Member
Licensed User
Longtime User
I am trying to add a variable number of label date headings to a panel created in the program and keep getting an error message "Only 'Length' is supported by arrays." I have done similar things before without any issues so not sure what I am doing wrong this time. The error occurs on the first initialize within the for/next loop.

B4X:
    Dim q As Panel
    q.Initialize("pnlSummaryTotalsBack")
    q.Color = Colors.Black
    Activity.AddView(q, 2dip, 50dip, 1020dip, 380dip)
   
    Dim p As Panel
  p.Initialize("pnlSummaryTotals")
    p.Color = Colors.ARGB(255, 52, 100, 0)
    q.AddView(p, 2dip, 2dip, 1016dip, 376dip)
   
' Add summary basic details
    For x = 0 To intTotalDates
        lblDateFrom.Initialize("lblDateFrom")
        lblDateFrom.TextColor = Colors.Black
        lblDateFrom.Text = tabDates(x,0)
        lblDateFrom.TextSize = 14
        lblDateFrom.Typeface = Typeface.MONOSPACE
        lblDateFrom.Gravity = Gravity.CENTER
        p.AddView(lblDateFrom, 360dip + ((7 - intTotalDates) + (x * 45dip)), 10dip + ((14 - intTotalStores) + (x * 10dip)), 80dip, 20dip)
        lblDateFrom(x) = p
        lblTo.Initialize("lblTo")
        lblTo.TextColor = Colors.Black
        lblTo.Text = "To"
        lblTo.TextSize = 14
        lblTo.Typeface = Typeface.MONOSPACE
        lblTo.Gravity = Gravity.CENTER
        p.AddView(lblTo, 360dip + ((7 - intTotalDates) + (x * 45dip)), 24dip + ((14 - intTotalStores) + (x * 10dip)), 80dip, 20dip)
        lblTo(x) = p
        lblDateTo.Initialize("lblDateTo")
        lblDateTo.TextColor = Colors.Black
        lblDateTo.Text = tabDates(x,1)
        lblDateTo.TextSize = 14
        lblDateTo.Typeface = Typeface.MONOSPACE
        lblDateTo.Gravity = Gravity.CENTER
        p.AddView(lblDateTo, 360dip + ((7 - intTotalDates) + (x * 45dip)), 40dip + ((14 - intTotalStores) + (x * 10dip)), 80dip, 20dip)
        lblDateTo(x) = p
    Next

Thanks.
 

Big Dave

Member
Licensed User
Longtime User
To Mangojack

Can't see your message posted here but it came through as an email to me. To answer your question the declaration is done in Sub Globals...

B4X:
    Dim pnlSummaryTotalsBack As Panel
    Dim pnlSummaryTotals As Panel
    Dim lblDateFrom(7) As Label
    Dim lblTo(7) As Label
    Dim lblDateTo(7) As Label

Hope this helps.

Thanks for looking.
 
Upvote 0

mangojack

Expert
Licensed User
Longtime User
all references to the Labels to include the array counter ..
B4X:
lblDateFrom (x) .Initialize("lblDateFrom")   
  p.AddView(lblDateFrom (x), 360dip + ((7 - intTotalDates) + (x * 45dip)), 10dip + ((14 - intTotalStores) + (x * 10dip)), 80dip, 20dip)
  lblDateFrom (x) = p

but this line
B4X:
lblDateFrom (x) = p
confuses me .. but I am easily confused !
 
Last edited:
Upvote 0

Big Dave

Member
Licensed User
Longtime User
I have now got something to work albeit needing some fine tuning!!

B4X:
    Dim pnlSummaryTotalsBack As Panel
    Dim pnlSummaryTotals As Panel
    Dim lblDateFrom As Label
    Dim lblTo As Label
    Dim lblDateTo As Label

B4X:
    Dim q As Panel
    q.Initialize("pnlSummaryTotalsBack")
    q.Color = Colors.Black
    Activity.AddView(q, 2dip, 50dip, 1020dip, 380dip)
   
    Dim p As Panel
  p.Initialize("pnlSummaryTotals")
    p.Color = Colors.ARGB(255, 52, 100, 0)
    q.AddView(p, 2dip, 2dip, 1016dip, 376dip)
   
' Add summary basic details
    For x = 0 To intTotalDates
        lblDateFrom.Initialize("lblDateFrom")
        lblDateFrom.TextColor = Colors.Black
        If tabDates(x,0) <> "" Then
            lblDateFrom.Text = tabDates(x,0).SubString2(4,6) & "/" & tabDates(x,0).SubString2(2,4) & "/" & tabDates(x,0).SubString2(0,2)
        End If
        lblDateFrom.TextSize = 14
        lblDateFrom.Typeface = Typeface.MONOSPACE
        lblDateFrom.Gravity = Gravity.CENTER
        p.AddView(lblDateFrom, 360dip + ((7 - intTotalDates) + (x * 45dip)), 10dip + ((14 - intTotalStores) + (x * 10dip)), 80dip, 20dip)
        lblTo.Initialize("lblTo")
        lblTo.TextColor = Colors.Black
        lblTo.Text = "To"
        lblTo.TextSize = 14
        lblTo.Typeface = Typeface.MONOSPACE
        lblTo.Gravity = Gravity.CENTER
        p.AddView(lblTo, 360dip + ((7 - intTotalDates) + (x * 45dip)), 24dip + ((14 - intTotalStores) + (x * 10dip)), 80dip, 20dip)
        lblDateTo.Initialize("lblDateTo")
        lblDateTo.TextColor = Colors.Black
        lblDateFrom.Text = tabDates(x,1).SubString2(4,6) & "/" & tabDates(x,1).SubString2(2,4) & "/" & tabDates(x,1).SubString2(0,2)
        lblDateTo.TextSize = 14
        lblDateTo.Typeface = Typeface.MONOSPACE
        lblDateTo.Gravity = Gravity.CENTER
        p.AddView(lblDateTo, 360dip + ((7 - intTotalDates) + (x * 45dip)), 40dip + ((14 - intTotalStores) + (x * 10dip)), 80dip, 20dip)
    Next

I now get warning messages saying that the two panels created in the code are not initialized so I may create the panels in the designer and just add the rest in code.

Thanks everyone.
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
As a guess as we cant see the rest of the code, but, If you are accessing the panels outside of the sub that you created them in then they need to be dimmed in sub globals.
 
Upvote 0

Big Dave

Member
Licensed User
Longtime User
try this when you initialize your Labels array ..

B4X:
  For x = 0 To intTotalDates
     lblDateFrom (x) .Initialize("lblDateFrom")


mj

My original thought was that I needed an array for the date labels as they are part of the for/next loop. However as my revised code seems to give me the dates on the panel and they are there for information only do I need to create arrays. Would welcome your advice on this as although I am a seasoned programmer I am still learning this language and would like to get it right.

Many thanks for your help.

David
 
Upvote 0

mangojack

Expert
Licensed User
Longtime User
Dave .. you are creating an array of labels from within the loop .. as many as is necessary .. (intTotalDates).

I'll leave it for the guru's to advise if this is the correct approach..
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
maybe you post complete code here and describe what exactly you want to do and/or with what you have problems with...
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
I am trying to add a variable number of label date headings to a panel created in the program and keep getting an error message "Only 'Length' is supported by arrays." I have done similar things before without any issues so not sure what I am doing wrong this time. The error occurs on the first initialize within the for/next loop.

B4X:
    Dim q As Panel
    q.Initialize("pnlSummaryTotalsBack")
    q.Color = Colors.Black
    Activity.AddView(q, 2dip, 50dip, 1020dip, 380dip)
  
    Dim p As Panel
  p.Initialize("pnlSummaryTotals")
    p.Color = Colors.ARGB(255, 52, 100, 0)
    q.AddView(p, 2dip, 2dip, 1016dip, 376dip)
  
' Add summary basic details
    For x = 0 To intTotalDates
        lblDateFrom.Initialize("lblDateFrom")
        lblDateFrom.TextColor = Colors.Black
        lblDateFrom.Text = tabDates(x,0)
        lblDateFrom.TextSize = 14
        lblDateFrom.Typeface = Typeface.MONOSPACE
        lblDateFrom.Gravity = Gravity.CENTER
        p.AddView(lblDateFrom, 360dip + ((7 - intTotalDates) + (x * 45dip)), 10dip + ((14 - intTotalStores) + (x * 10dip)), 80dip, 20dip)
        lblDateFrom(x) = p
        lblTo.Initialize("lblTo")
        lblTo.TextColor = Colors.Black
        lblTo.Text = "To"
        lblTo.TextSize = 14
        lblTo.Typeface = Typeface.MONOSPACE
        lblTo.Gravity = Gravity.CENTER
        p.AddView(lblTo, 360dip + ((7 - intTotalDates) + (x * 45dip)), 24dip + ((14 - intTotalStores) + (x * 10dip)), 80dip, 20dip)
        lblTo(x) = p
        lblDateTo.Initialize("lblDateTo")
        lblDateTo.TextColor = Colors.Black
        lblDateTo.Text = tabDates(x,1)
        lblDateTo.TextSize = 14
        lblDateTo.Typeface = Typeface.MONOSPACE
        lblDateTo.Gravity = Gravity.CENTER
        p.AddView(lblDateTo, 360dip + ((7 - intTotalDates) + (x * 45dip)), 40dip + ((14 - intTotalStores) + (x * 10dip)), 80dip, 20dip)
        lblDateTo(x) = p
    Next

Thanks.


I have not read the whole thread slowly, but I do not see the declaration of lblDateFrom, lblTo and lblDateTo, which should be inside the loop.
 
Upvote 0
Top