How do you find the Maximum value out of a big list of numbers?


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: How do you find the Maximum value out of a big list of numbers?

  1. #1
    Aaron Guest

    How do you find the Maximum value out of a big list of numbers?


    I have a big list of numbers in a txt file, and I want to write the VB code
    so it will automatically find the maximum number and put it in a label.
    Is there a max function in VB? Please help. Thanks.

    Aaron

  2. #2
    Russell Jones Guest

    Re: How do you find the Maximum value out of a big list of numbers?

    No, but you can convert all the values from text to numbers, put them in an
    Array or ArrayList, and then use the Sort method to sort them in ascending
    order. The maximum value is then the last item in the sorted array. Here's
    an example.

    Dim list As New ArrayList()
    list.AddRange(New Double() {3, 8, 6, 1, 2})
    list.Sort()
    Debug.WriteLine(list.Item(list.Count - 1)) ' writes 8


    "Aaron" <adogg18@hotmail.com> wrote in message news:3d21cb66$1@10.1.10.29...
    >
    > I have a big list of numbers in a txt file, and I want to write the VB

    code
    > so it will automatically find the maximum number and put it in a label.
    > Is there a max function in VB? Please help. Thanks.
    >
    > Aaron




  3. #3
    Aaron Guest

    Re: How do you find the Maximum value out of a big list of numbers?


    Good idea... I will try that.

    "Russell Jones" <arj1@nospam.northstate.net> wrote:
    >No, but you can convert all the values from text to numbers, put them in

    an
    >Array or ArrayList, and then use the Sort method to sort them in ascending
    >order. The maximum value is then the last item in the sorted array. Here's
    >an example.
    >
    > Dim list As New ArrayList()
    > list.AddRange(New Double() {3, 8, 6, 1, 2})
    > list.Sort()
    > Debug.WriteLine(list.Item(list.Count - 1)) ' writes 8
    >
    >
    >"Aaron" <adogg18@hotmail.com> wrote in message news:3d21cb66$1@10.1.10.29...
    >>
    >> I have a big list of numbers in a txt file, and I want to write the VB

    >code
    >> so it will automatically find the maximum number and put it in a label.
    >> Is there a max function in VB? Please help. Thanks.
    >>
    >> Aaron

    >
    >



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center