Layout Variables and dip

tdocs2

Well-Known Member
Licensed User
Longtime User
Greetings to all. And once more, I find myself asking a newbie question and thanking you in advance for answering it.

Hypothetical Case:
Multiple panels in an activity.
The top of the panel (or Left) varies depending upon a condition.
I want to set the value for top once based on the condition;
e.g., If A then panel_top=80 (Dim panel_top as Int)
Then, I assign panel_top to the layout variable top for all the panels.

Question:
I normally use dip for assigning this type of value; e.g., P.top=80dip.
The layout variable top is an integer.
How can I combine P.top=panel_top & "dip"?

Best regards.
 

tdocs2

Well-Known Member
Licensed User
Longtime User
Thank you, Klaus and follow up

Thank you, Klaus.

I must have not been clear.

If Monday, I want all the panels in the activity to be top=10dip
If Tuesday, top=20dip
If Weds, top=30dip

I can establish the hypothetical condition (day of week) in my app, and I can derive the value it requires, 10, 20, or 30. However, I cannot find a way to concatenate the integer value and "dip". The only solution I have found is to duplicate the code for each panel:

If Monday, panel1.top=10dip
If Monday, panel2.top=10dip
If...
If...
If Monday, panelx.top=10dip

Thank you, again, Klaus.
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
Sorry, but I still don't understand exactly your problem.
From what I understand this is one possibilty:
B4X:
Dim pnlTop as Int
If WeekDay = "Monday" Then
    pnlTop = 10dip
Else If WeekDay = "Thuesday" Then
    pnlTop = 20dip
Else If WeekDay = "Wednesday" Then
    pnlTop = 30dip.
'
End If
panel1.top = pnlTop 
panel2.top = pnlTop 
'
panelX.top = pnlTop
You could also define an array of panels.
Then the last part of the above example could be:
B4X:
For i = 0 to NbPanels -1
    panel(i).top = pnlTop 
Next
You need to adapt the test If WeekDay = "Monday" Then to your needs, because I don't know how you define the day of the week.
Depending on that there would be oher solutions.
If the date is in ticks you can use DateTime.GetDayOfWeek.

Instead of
pnlTop = 10dip
you could also use
pnlTop = DipToCurrent(10)

Best regards.
 
Last edited:
Upvote 0

tdocs2

Well-Known Member
Licensed User
Longtime User
Exactly correct

Hello, Klaus.

Thank you for taking the time to answer the question. You understood the question perfectly and answered it correctly.

I did not think (and should have tried) to assign a dip value to an Int variable. Thus, the code in your answer works:

B4X:
Dim pnlTop as Int
...
pnlTop = 10dip

I thought dip could not be assigned outside of layout properties. Really, a newbie question and truly a patient and expert answer.

Best regards,

Sandy
 
Upvote 0
Top