11-02-2012 11:42 AM
I am trying to Dim variables that have different numbers of iterations each time I run a script. However, I don't think I can use a variable within a Dim statement. Is there another way to do this?
What I think I want to do is this:
Dim n, xsum, xavg
xsum=0
xavg=0
m=InputBox("How many runs should be averaged?") 'For example, m = 3
n=m-1 'Convert number of runs to base zero; for example, n = 2
Dim x(n)
For i= 0 to n
x(i)=i
Next 'For example, x(0) = 0, x(1) = 1, x(2) = 2
For i=0 to n
xsum=xsum+x(i)
Next 'For example, the completed xsum = 3
xavg=xsum/m 'For example, xavg = 1
Solved! Go to Solution.
11-03-2012 08:10 PM
Hi sraykens,
ReDim x(n) should work. I always Dim my variables as scalars and use ReDim to turn them into arrays when needed-- it works out better for several reasons.
Brad Turpin
DIAdem Product Support Engineer
National Instruments