I'm constructing an array dimmed (1-11). The items that I am placing inside are dimmed double. I want to look through the array, once completed, and pick three values that are the closest to a nominal number. How do I do this?
Printable View
I'm constructing an array dimmed (1-11). The items that I am placing inside are dimmed double. I want to look through the array, once completed, and pick three values that are the closest to a nominal number. How do I do this?
Sounds a little like homework. hmm.
You need to work this some on your own.
Code:Dim a(11) as Double
Dim close(11) as double
Dim nominal as Double
Dim tmp as Double
For x = 1 to 11 ' load the arra - you work on this one
a(x) = somethingDimmedAsDouble
Next x
for x = 1 to 11 ' find the differences
closest(x)=abs(a(x)-nominal)
next x
For x = 1 to 10 ' sort from smallest to largest
for y = 1 to 10
if (a(y) > a(y+1) then
tmp = a(y)
a(y)=a(y+1)
a(y+1)=tmp)
end if
next y
next x
' the first three elements in the close() array are your answer
For x = 1 to 3
Me.Print close(x)
next x