Solved

Create a variable within the subroutine

Posted on 2002-05-31
5
174 Views
Last Modified: 2010-05-02
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.
0
Comment
Question by:Cindy75
5 Comments
 
LVL 18

Expert Comment

by:bobbit31
ID: 7047565
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
0
 
LVL 15

Accepted Solution

by:
ameba earned 100 total points
ID: 7047662
' add this module to your project
Option Explicit

' usage: in debug window type:    ?gen("Dim var%i% As Single", 1, 40)
'
Public Function gen(line As String, first As Integer, last As Integer, Optional SaveToClipboard As Boolean = True)
    Dim i As Long, s As String
   
    For i = first To last
        s = s & Replace(line, "%i%", CStr(i)) & vbCrLf
    Next
    If SaveToClipboard Then
        Clipboard.Clear
        Clipboard.SetText s
    End If
    gen = s
End Function
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 7047825
hearing...
0
 
LVL 16

Expert Comment

by:twalgrave
ID: 7896973
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
0
 

Expert Comment

by:SpideyMod
ID: 7912911
per recommendation

SpideyMod
Community Support Moderator @Experts Exchange
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

815 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now