variable names as lbl names

drhamel

Member
Licensed User
Longtime User
I hope I can explain this. I am coming from the PHP world and somehting that his easy in PHP I am not sure is possible in B4A. I have the code below. It is a number pad for a special calulator i am making. My question is can I set the label name with a variable. So in effect if active cell=1 then LabelVariable = lblDriveEfficiency and if active_cell=2 then LabelVariable = lblDriveEfficiency.

Then for example, I wouldn't have to retype the code below for every label (input) I have. I could just have any of the statements be

{Label_Variable}.text.Text = {Label_Variable}.Text & Send.Tag

Instead of having to code for every label (input) I have.

Thanks,

David



B4X:
Dim Send As Button
   Send = Sender
   Select Send.Tag
   Case "BS"
      If lblDriveEfficiency.Text.Length >0 Then
         lblDriveEfficiency.Text = lblDriveEfficiency.Text.SubString2(0,lblDriveEfficiency.Text.Length - 1)
      End If
   Case "." 'Check for and disallow multipole decimal points
      If lblDriveEfficiency.Text.Contains(".") Then
      Else
         lblDriveEfficiency.Text = lblDriveEfficiency.Text & Send.Tag
      End If
   Case Else
      lblDriveEfficiency.Text = lblDriveEfficiency.Text & Send.Tag
   End Select
 

drhamel

Member
Licensed User
Longtime User
I have 11 buttons (0-9, Backspace, and "." decimal. When you click each label it highlights yellow and sets a global variable to active. I just want a way to replace the label name in the above code depending on my active variable.
 
Upvote 0

drhamel

Member
Licensed User
Longtime User
To be honest I would love to make this into a global subroutine of some sort where I pass the label_name of the label_name.text I want to set.
 
Upvote 0

nfordbscndrd

Well-Known Member
Licensed User
Longtime User
I have 11 buttons (0-9, Backspace, and "." decimal. When you click each label it highlights yellow and sets a global variable to active. I just want a way to replace the label name in the above code depending on my active variable.

You might want to look at http://www.b4x.com/forum/basic4andr.../11631-custom-keyboard-creator-interface.html

The code uses the same routines for entering text into different labels. Not sure from your post if you are trying to do essentially the same thing or not.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
I meant something like:
B4X:
Sub Globals
   Dim CurrentTargetLabel As Label
End Sub

Sub ChooseLabel (lbl As Label)
   CurrentTargetLabel = lbl
End Sub

Dim Send As Button
    Send = Sender
    Select Send.Tag
    Case "BS"
        If CurrentTargetLabel.Text.Length >0 Then
            CurrentTargetLabel.Text = CurrentTargetLabel.Text.SubString2(0,CurrentTargetLabel.Text.Length - 1)
        End If
 
Upvote 0
Top