Solved

Create a variable within the subroutine

Posted on 2002-05-31
5
175 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

830 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