Discussion:
Runtime Variables?
(too old to reply)
Martin Trump
2003-08-22 19:12:59 UTC
Permalink
Hi, I would like to know if there is a way to create run-time
variables. For example,
for I = 1 to 10
dim "team" & I
next I
Tim, maybe side step the problem with (untested code):-

Dim x(0) (As whatever)

Then in your program, repeatedly

Redim (Preserve) x(Ubound(x) + 1)

Gives you an unlimited number of variables x().

Just a guess.

HTH.
--
Martin Trump
Tim^^BOB
2003-08-27 00:28:24 UTC
Permalink
Post by Martin Trump
Hi, I would like to know if there is a way to create run-time
variables. For example,
for I = 1 to 10
dim "team" & I
next I
Tim, maybe side step the problem with (untested code):-
Dim x(0) (As whatever)
Then in your program, repeatedly
Redim (Preserve) x(Ubound(x) + 1)
Gives you an unlimited number of variables x().
Just a guess.
HTH.
Thanks! I guess that might work but that leads me to another problem
(this might be a bit newbish), the variables i need have to be records
containing a couple of different values. I'm not sure how to access
invividual values within a record inside of an array. I'm pretty sure
that something like,
Label1.caption = x(5.name)
wont work. Any ideas on that?
Thanks again.
Demosthenes
2003-08-27 01:42:11 UTC
Permalink
Post by Tim^^BOB
Label1.caption = x(5.name)
wont work. Any ideas on that?
If I understand you correctly, you could use a user-defined type.

Type UserDefinedVariable
Value as Integer
Name as String
End Type

Dim x(0) as UserDefinedVariable

Redim (Preserve) x(Ubound(x) + 1)

...etc...

Label1.Caption = x(5).Name
Tim^^BOB
2003-08-27 15:03:29 UTC
Permalink
Post by Demosthenes
Type UserDefinedVariable
Value as Integer
Name as String
End Type
Dim x(0) as UserDefinedVariable
Redim (Preserve) x(Ubound(x) + 1)
...etc...
Label1.Caption = x(5).Name
Thanks guys! I guess i just didn't get that syntax right or
something... x(5).name instead of x(5.name) those 5 little characters
stalled the production of my entire program! Demosthenes your right
thats exactly what I meant. One last question if I could,

Redim (Preserve) x(Ubound(x) + 1)

I don't really understand the purpose of this line... couldn't I just
use 'Redim x(10)' or something? The value is entered into a textbox by
the user, so it is easily accessable by the program. If I'm wrong
here, would someone mind explaining why I need the Ubound in there?

Thanks!!
Martin Trump
2003-08-27 16:45:01 UTC
Permalink
Post by Martin Trump
Tim, maybe side step the problem with (untested code):-
Dim x(0) (As whatever)
Then in your program, repeatedly
Redim (Preserve) x(Ubound(x) + 1)
Tim, looking back I made a slip. That should have been:-
Dim x() to create a _dynamic_ array then Redim Preserve x(whatever).

For your later question (multiple values) use such as:-
Redim Preserve x(5,whatever)

That'd give you half a dozen values in each.

HTH
--
Martin Trump
Tim^^BOB
2003-08-28 17:24:22 UTC
Permalink
Thanks guys. That should be about it for me and if I have any more
questions Ill be sure to post them here. This should about finish my
program! Thanks alot!

Loading...