Results 1 to 4 of 4
  1. #1
    2 Star Lounger
    Join Date
    May 2002
    Location
    USA
    Posts
    190
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Finding smallest/Largest number from file (VB.NET)

    Ok I know this is probably pretty easy but it's bugging me. How can I determine what the smallest and the largest number is when I'm reading a list of numbers out of a specific text file. For example: Say I have a text file with these numbers in it

    8
    2
    0
    9
    1
    2
    4
    3

    No through reading this file how do I determine that 9 is the largest number and 0 the smallest? Any help is appreciated

  2. #2
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Finding smallest/Largest number from file (VB.NET)

    Max and Min aggregate functions are supported in VS.Net, but you could simply populate a 1-dimensional array with the values in the text file and use the array's sort method, then return the first and last values by referencing index 0 and index count -1.
    Charlotte

  3. #3
    2 Star Lounger
    Join Date
    May 2002
    Location
    USA
    Posts
    190
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Finding smallest/Largest number from file (VB.NET)

    well what I ended up doing, since this file is set up in a Loop, is something like this:

    num = sr.ReadLine

    If num > largest then
    largest = num
    end if

    If num < smallest
    smallest = num
    end if

    Thats a section of the code. Everything is declared and it works. Thanks for the help.

  4. #4
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Finding smallest/Largest number from file (VB.NET)

    Except for the readline, that's the same way you might do it in VB/VBA. I assumed you were looking for something more .Net specific. <img src=/S/doh.gif border=0 alt=doh width=15 height=15>
    Charlotte

Posting Permissions

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