Our full technical support staff does not monitor this forum. If you need assistance from a member of our staff, please submit your question from the Ask a Question page.

### Total for consegutive variables

smile Mar 24, 2020 08:01 AM

Hi to All,

maybe it's a simple thing, but it just doesn't come to mind.

I have 25 variables with the same name, for example "public var (25)"

How can I get a variable that is the total of some consecutive of them? for example:

total5 = var1 + var2 + var3 + var4 + var5
or
total23 = var1 + var2 + var3 + ............ var23

Thanks

Regards

Smile

JDavis Mar 24, 2020 09:12 AM

To simplify it, you can use a loop to do the math.

```Public ValuesToTotal As Long
Public Result
Public var(25)

Dim i As Long

'Main Program
BeginProg
Scan (1,Sec,0,0)

Result = 0
For i = 1 To ValuesToTotal
Result += var(i)
Next i

NextScan
EndProg
```

smile Mar 25, 2020 01:23 AM

Hi JDavis many thanks for reply.

I did not understand very well, but your example has stimulated my imagination ;-)

I still have to do a test, but it might work. I have to try like this:

For n=1 To 25

Total(n)=0

For i=1 To n
Total(n)=Total(n)+VAR(i)
next i
next n

........

what I may not have explained well, is that there are as many totals, as many as the VARs.

regarsd

Smile