I've attached a piece of my code that I'm hoping someone can help with. I'm running Access 2010.
What I'm trying to do is this:
I have a table listing sizes
4
3
2
1
.9
.8
.7
.6
.5
.4
.3
.2
.1
The array gbArray() in the code has been assigned the values from the table. The array is then sorted in descending order. I have a form with a target number (i.e. 1.1), which is assigned to the variable "target".
I want to sum each combination of numbers from the array and return combinations that equal the target value.
My problem is, for example, if 1.1 is my target value, when gbArray(one)=1 and gbArray(two)=.1, Access does not recognize that 1+.1=1.1. However, when gbArray(one)=.1 and gbArray(two)=1, then Access can recognize that .1+1=1.1. This doesn't make any sense to me.
The reason for the six decimal rounding of gbArray() is because that's the only way I could get any remotely valid math. Without this, I would get things like 1+1=1.999999995. I've regularly had math issues like this in Excel and rounding has usually solved the problem.
Help, please.
Code:
DIM gbArray() As Single, target As Single
For one = 1 To UBound(gbArray)
If gbArray(one) > target Then GoTo nextone
For two = 1 To UBound(gbArray)
If two >= one Then GoTo skip_stepone
If Round(gbArray(one), 6) + Round(gbArray(two), 6) = Round(target, 6) Then
Debug.Print gbArray(one) & "; " & gbArray(two)
done = 1
End If
skip_stepone:
Next two
nextone:
Next one
If done = 1 Then Exit Sub