|
Post by johnnyd on Mar 15, 2019 7:47:01 GMT -5
Hi good people,
Its been a while since I was here but still alive & kicking!
Is there a way of referencing variables the same way as you can do with handles?
Handles:
(5 textboxes: #main.1, #main.2, #main.3, #main.4, #main.5)
for a=1 to 5 h$="#main."+str$(a) #h$,str$(a) next a
so 5 textboxes are filled with the incrementing value of a.
So with variables:
aa=1 bb=2 cc=3 dd=4 ee=5
vars$="aa,bb,cc,dd,ee" for a=1 to 5 h$=word$(vars$,a,",") ;get the variable name from a list #h$,[new value] ;give it the new value next a
so the variables have changed: aa=2, bb=4, cc=6, dd=8, ee=10
This would make changing variable values much easier and the code shorter if there are numerous variables you want to change in one go, as in a for/next loop
I know dimensioned arrays is one way to do this by referencing the array elements, but how memorable & meaningful are these when you're coding?!? If you have e.g. a 50 x 50 array, you have to know exactly what each row & column is for, especially when debugging and trying to follow the changes. As the variable name is referenced directly, you can track them easily.
Just a thought!
John.
|
|
|
Post by Rod on Mar 15, 2019 12:26:19 GMT -5
How about giving the array() indexes meaningful names.
Z=array(Object,Ypos)
Xpos, Ypos and Zpos for example can be global,defined at the start. As 1,2,3
|
|
|
Post by Brandon Parker on Mar 16, 2019 18:51:47 GMT -5
I think we need a better explanation of what you are trying to do.
Here is how one would evaluate a variable from a list of variables in a string separated by commas such as you show. Is this what you are asking?
aa=1 bb=2 cc=3 dd=4 ee=5
vars$ = "aa,bb,cc,dd,ee" For i = 1 To 5 Print Eval$(Word$(vars$, i, ",")) Next i
Wait
{:0)
Brandon Parker
|
|