Solved

Create a variable within the subroutine

Posted on 2002-05-31
5
173 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
Comment Utility
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
Comment Utility
' 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
Comment Utility
hearing...
0
 
LVL 16

Expert Comment

by:twalgrave
Comment Utility
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
Comment Utility
per recommendation

SpideyMod
Community Support Moderator @Experts Exchange
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

762 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

5 Experts available now in Live!

Get 1:1 Help Now