Link to home
Start Free TrialLog in
Avatar of Cindy75
Cindy75

asked on

Create a variable within the subroutine

I need code to create multiple variables from the subroutine.  I need to create DS1 - DS40.  Those need to be the variable names, but I'd like the program to create them without having to type them all in.  If I know how to do this, I can apply it to multiple programs.

For T = 1 to 40

DS(T) = rnd *10

Next T

I need the program to create variables based on a counter.  These variables have to be declared as single.  I would like the simplest way to do this.
Avatar of bobbit31
bobbit31
Flag of United States of America image

why not use an array?

Dim numVars As Integer
Dim i As Integer

numVars = 40

Dim DS() As Single
ReDim DS(1 To numVars)

For i = 1 To UBound(DS)
    DS(i) = Rnd * 10
Next
ASKER CERTIFIED SOLUTION
Avatar of ameba
ameba
Flag of Croatia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Richie_Simonetti
hearing...
Avatar of twalgrave
twalgrave

No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:
- answered by ameba
Please leave any comments here within the
next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER !

twalgrave
Cleanup Volunteer
per recommendation

SpideyMod
Community Support Moderator @Experts Exchange