Results 1 to 2 of 2

Thread: "Best Fit" values in an array

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jul 2002
    Posts
    87

    Question "Best Fit" values in an array

    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?

  2. #2
    Frenzied Member
    Join Date
    Jul 2002
    Posts
    1,370
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width