Hi guys!
This might be hard to explain, but I'll do my best. Consider the following pseudo-code:
How can I do this without having to do this with lots of IF's or CASE statements?
I would like to do more advanced stuff like creating variables on the fly:
Is there anyone who can help me?
This might be hard to explain, but I'll do my best. Consider the following pseudo-code:
B4X:
Dim a, b, c, d, e, f, g, ... As Int
GetUserInput("Which variable? ", VarName)
SetVar(VarName, 10)
'Output:
'(c = 0)
'Which variable? c
'(c = 10)
How can I do this without having to do this with lots of IF's or CASE statements?
B4X:
Sub SetVar(VarName as String, Value as Int)
If VarName = "a" Then a = value
If VarName = "b" Then b = value
If VarName = "c" Then c = value
If VarName = "d" Then d = value
...
End Sub
I would like to do more advanced stuff like creating variables on the fly:
B4X:
GetUserInput("Create which variable? ", VarName)
SetVar(VarName, 10)
'Output:
'(in the beginning, the variable "c" doesn't exist.)
'Which variable? c
'(the "c" variable is created through something like:
' Dim !VarName! As Int
' !VarName! = 10)
Is there anyone who can help me?
Last edited: