DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

Trying to define multiple versions of one variable from input box

Solved!
Go to solution

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

Steve Aykens

9172 8-slot cDAQ chassis OR 9162 cDAQ USB carrier
9234 4-Ch IEPE Sound/Vibration Input Module
9219 (2) 4-Ch Universal Input Module
9213 (3) 16-Ch Thermocouple Input Module
Signal Express 2012 with Sound and Vibration Suite
Labview 2012
DIAdem 2012
0 Kudos
Message 1 of 2
(4,282 Views)
Solution
Accepted by topic author sraykens

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

0 Kudos
Message 2 of 2
(4,274 Views)