Android Question defining Variables

Mark.S

Member
Licensed User
having declared two labels in Sub_Globals
why can't the the .text of these labels be read/written by each other.
They there in different subs, but in the same module.
getting an " should first be initialized err"

how can these values be passed between these labels?
 

Mark.S

Member
Licensed User
Hi Erel,
I'm not using the designer at all.
Dimmed an array of 20 labels in Sub_Globals.
Assigned all their property's and initialized them in a sub
their .text values are being re-assigned in their _click subroutine
it's when I try to read/write their .text in a third sub the err accrues
it appears that this sub has no knowledge of the view

btw Erel thanks for thanks for helping!!
 
Upvote 0

Mark.S

Member
Licensed User
Erel,

it will be a bespoke program for analyzing fruit machine performance.
and cash collection data. designed to work on a 7" pad only.

its my first ever program
 

Attachments

  • Meter Capture.zip
    51.4 KB · Views: 209
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
B4X:
            If SelectedPanel = 2 Then ' Copy value of selected meter to keyboard result box

'ERROR *******
            Log(lbl.Tag)

lbl.Tag value is 14, and...
B4X:
'Create Meter Inputs labels
    Cd.Initialize2 (Colors.ARGB (255,255,255,255),0,2, Colors.Black)
    For X =0 To 13  <-------
        lblMRinput(X).Initialize("MeterInput")
 
Upvote 0

Mark.S

Member
Licensed User
Thanks LucaMs,
So obvious!
lesson one. DON'T use public variables unless you have to!
I'm very grateful to all you experts out there, this community is very supportive.
 
Upvote 0

NJDude

Expert
Licensed User
Longtime User
I don't understand why you're not using the designer, but, if you insist on doing everything by code then remove line 42:
B4X:
 Activity.LoadLayout("Main")

Also, you mentioned that your app it's designed for 7 inch tablets, well, this is how it looks on one of mine - Screenshot

Using the designer is the way to go.
 
Last edited:
Upvote 0

Mahares

Expert
Licensed User
Longtime User
So how do you define an array of views in the designer?
here is an example:
B4X:
'BELOW 2 LINES IN GLOBALS
Dim C1pr, Chem1pr, C2pr, Chem2pr, C3pr, Chem3pr, C4pr, Chem4pr, C5pr, Chem5pr As Label 
Dim CChem() As Label

'Then after you load the layout in Activity_Create with these views, you enter this line:
CChem = Array As Label(C1pr, Chem1pr, C2pr, Chem2pr, C3pr, Chem3pr, C4pr, Chem4pr, C5pr, Chem5pr)
 
Upvote 0

clydebamford

Member
Licensed User
Longtime User
ok, but just not practical if you have say 20 or 30 or more views that you can define and implement with a few lines in a loop. i use the designer but often find that i end up altering their properties in code to the point where it might have been easier not to bother? i always start with the designer but with a complex project the end product bears no resemblance to the the layout, but that's just me!
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…