I need to sum over a subset of elements in an array of doubles. As a simple example
consider an array of 10 elements:
Dim Array(1 To 10) As Double
where each element has been assigned some value. Is there a function in VB that will sum the first 5 elements? Obviously this can be solved using a loop but is there a one line solution? I would like to keep my code consise. I have tried using SUM but without success.
Thanks!
No, there is no built in summing function in VB6 that does what you want, but you can write one easily:
Please be aware I did not sytaz check this, so watch for typos. It can be used as follows:
You could modify the method to take another optional boolean to specifies if you will tolerate (ignore) out-of-bounds. Right now an error would be reaised if you asked to sum more elements than exist in the array.