There are several ways to do it in Basic4android.
In B4A all objects can be passed as parameters to other subs. So instead of passing the control name, you can now pass the control.
If you describe your use case I can give you an example.
thanks for your answer.
I have have a Timer-Sub which checks if there is a collision between a ball and a pad:
B4X:
Sub tmBall_Tick
...
'check collision ball and pad
'1. check collision ball and players pad
If (imgBall.Top<=pnlPlayer.Top+pnlPlayer.Height) AND (imgBall.Left>=pnlPlayer.Left-imgBall.Width-1 AND imgBall.Left<=pnlPlayer.Left+pnlPlayer.Width+1) Then
collision(pnlPlayer) [COLOR="Green"]'we call the sub with the name of the pad[/COLOR]
End If
'2. check collision ball and computers pad
If (imgBall.Top+imgBall.Height>=pnlComputer.Top) AND (imgBall.Left>=pnlComputer.Left-imgBall.Width-1 AND imgBall.Left<=pnlComputer.Left+pnlComputer.Width+1) Then
collision(pnlComputer)
End If
...
End Sub
The Sub Collision control the ongoing game depending on which kind of pad has the collision:
B4X:
Sub Collision(pad)
'we detect the position where the pad hit the ball
pos=imgBall.Left-pad.Left+imgBall.Width [COLOR="Red"]<== doesn't work cause pad is a String[/COLOR]
If pad="pnlComputer" Then
[COLOR="DarkOrange"] do something[/COLOR]
[COLOR="darkorange"]... and so on[/COLOR]
End Sub
I know that I can write to subs Collision (i.e. coll1, coll2) and call them depending on the kind of pad. But how can I realize it with only one sub using parameters?
in B4PPC we can use the control keyword to access a control using a string instead of its name. i.e. Control("name",Panel).Width
How can we do this with B4A?
mhc
Seems, no reply to this question, how to address the existing views, if we know a name common part ?
Say, check states of "CheckBox1", "CheckBox2", "CheckBox3"....in a loop, addressing views like "CheckBox" + i.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.