Variabe names build with iteration

grobi71

Member
Licensed User
Longtime User
Hallo all,

is it possible in B4A to appand Chars to Variable names?

Example:

Dim btn0, btn1, btn2, btn3, btn4, btn5, btn6, btn7, btn8, btn9 As Button
Dim Nr As Byte

for Nr = 0 to 9
btn&"Nr".Top = 10
next

i know that Nr is not a Char in this example.

Grobi
 

klaus

Expert
Licensed User
Longtime User
is it possible in B4A to appand Chars to Variable names?
No, not directly.


But what you can do is to create an array of buttons like this:
B4X:
Dim btn0, btn1, btn2, btn3, btn4, btn5, btn6, btn7, btn8, btn9 As Button
Dim btns() As Button
btns = Array As Button(btn0, btn1, btn2, btn3, btn4, btn5, btn6, btn7, btn8, btn9)

For i = 0 To 9
    btns(i).Text = i
Next
Best regards.
 
Upvote 0

grobi71

Member
Licensed User
Longtime User
Hallo Klaus,

sometimes i think we are the onlyones here.
Thanks for your reply. I will test it. It's for the Convert Program to make it easier to read.

Great it works !!

Grobi
 
Last edited:
Upvote 0
Top