Frustration with Looping and Nulls

T

trekgoes2malaysia

I am trying to sum up values in an array. Since I am using real
numbers (with decimals), I have declared the array 'as single' .
Unfortunately, whenever one of the items in my array is null, this
causes an error when running a For ...Next routine since ACCESS cannot
seem to deal with nulls in a variable declared as single.

I tried to get around this problem by declaring the array as a variant
but then that resulted in the for ...next routine giving me a null
value for the sum if the last iteration of the routine is Null (rather
than the sum).

How can I get around this?? Below is my code:

j = 20.
For i=1 to j
sumx(i)=sumx(i) + 1
next
 
J

Jeff Boyce

That code appears to be adding "1" to each element in the array, not
"sum[ming] up values in an array".

If the "value" in the array is Null, can I assume you wish to add ... 0
(nothing)? If so, use the Nz() function to convert a Null to a zero.

--
Regards

Jeff Boyce
www.InformationFutures.net

Microsoft Office/Access MVP


Microsoft IT Academy Program Mentor
http://microsoftitacademy.com/
 
J

J_Goddard via AccessMonster.com

If you are declaring the array as single, none of the values should be "Null"
- they are 0 when you declare the array, and MS Access won't let you assign a
Null to a variable declared as single.

How do you put the values into the sumx() array?

Note Jeff's response too - your loop does not do what you are wanting to do.

John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top