Solved

Create a variable within the subroutine

Posted on 2002-05-31
5
177 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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 Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

734 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