Results 1 to 8 of 8

Thread: Loading an Array

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jul 2002
    Posts
    87

    Angry Loading an Array

    I would like to load an Array with values (the code below assigns a value to the s array(objData.s(1,0), then assigns this value to "XValue" which I want loaded into the array as separate points. I then want to view the high value & the low value of these 25 points within the array. How 2?


    Dim MeasurePoint As Single
    Dim XValue As Single

    Dim MyArray(1 To 25)
    For MeasurePoint = 1 To 25
    MLString "VT 1,0,0,-1,0,0,CO"
    XValue = objData.s(1, 0)
    MyArray(MeasurePoint) = XValue
    Next MeasurePoint



    Dim HighRetrieval As Single
    Dim LowRetrieval As Single
    HighRetrieval = UBound(MyArray)
    LowRetrieval = LBound(MyArray)

  2. #2

    Thread Starter
    Lively Member
    Join Date
    Jul 2002
    Posts
    87
    I don't know if I explained myself well, but the code as it currently is returns a value of "25" for the high and "1" for the low. I assume that my points are not loaded.

  3. #3
    Addicted Member run_GMoney's Avatar
    Join Date
    May 2002
    Location
    Detroit
    Posts
    186
    I could be way off on this, but doesn't UBound just return the index of the last number in the array? So if you've got 31 items declared Array(1 to 31) the UBound would return 31, not the actual item that's sittin in position 31

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Jul 2002
    Posts
    87
    that's what I'm seeing. So how do get the high value in the array?

  5. #5
    Addicted Member run_GMoney's Avatar
    Join Date
    May 2002
    Location
    Detroit
    Posts
    186
    Just for clarity, do you want the highest value in the array or the last item? For instance, if 25 is the highest value in an array, but 10 is the last item, UBound would refer to the Index of 10.

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Jul 2002
    Posts
    87
    I want the highest value, the 25, not the highest index (10).

  7. #7
    Addicted Member run_GMoney's Avatar
    Join Date
    May 2002
    Location
    Detroit
    Posts
    186
    Ok, here's what you need to do. Something like this:
    VB Code:
    1. Dim HighRetrieval as Integer
    2.  
    3. HighRetrieval = MyArray(0)
    4. 'sets the value of high retrieval to the first item
    5.  
    6. For i = 1 to UBound(MyArray)
    7.     If MyArray(i) > HighRetrieval Then
    8.         HighRetrieval = MyArray(i)
    9.     End If
    10. Next

    HighRetrieval should hold the highest number in the array. Same technique for LowRetrieval only with <.

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Jul 2002
    Posts
    87
    Thanks, I'll try that.

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