Results 1 to 6 of 6

Thread: Real quick array.min question

  1. #1

    Thread Starter
    Addicted Member Abrium's Avatar
    Join Date
    Feb 2007
    Location
    The Great State of Texas
    Posts
    205

    Real quick array.min question

    Hey guys,

    Can I do this to find the lowest value in an array greater than zero?

    Code:
     Dim findLowest() As Integer = {right, left, backRight, backLeft}
                    Dim theMove As Integer = findLowest.Min > 0
    Can't seem to find it on MSDN.

    Thanks.
    Abrium
    Asking the beginners questions so you don't have to!
    If by chance hell actually froze over and I some how helped you... Please rate.

  2. #2

    Thread Starter
    Addicted Member Abrium's Avatar
    Join Date
    Feb 2007
    Location
    The Great State of Texas
    Posts
    205

    Re: Real quick array.min question

    ok quick test says that I can't.

    Is there a way to execute that? I want the minimum number in the array greater than 0 without having to redim and remove values. Is that possible?
    Abrium
    Asking the beginners questions so you don't have to!
    If by chance hell actually froze over and I some how helped you... Please rate.

  3. #3

    Thread Starter
    Addicted Member Abrium's Avatar
    Join Date
    Feb 2007
    Location
    The Great State of Texas
    Posts
    205

    Re: Real quick array.min question

    I know that:
    Code:
               For i = 0 To findLowest.Length - 1
                        If findLowest(i) < theMove And findLowest(i) > 0 Then
                            findLowest(i) = theMove
                        End If
                    Next
    works.

    I just want to find a better case for when my array size isn't 3. Know what I mean.
    Abrium
    Asking the beginners questions so you don't have to!
    If by chance hell actually froze over and I some how helped you... Please rate.

  4. #4
    Frenzied Member
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,158

    Re: Real quick array.min question

    you can sort the array by using Array.Sort and get the first value from the array if the sort id ascending else last value in case of descending.

    I dont have idea about using the array sort function , never used it. May be should should consult the documentation

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: Real quick array.min question

    The Min method isn't a member of the Array class. It's an extension method, declared in the Enumerable class and extending the IEnumerable interface, which the Array class implements. You can use it in conjunction with other such extension methods, e.g.
    vb.net Code:
    1. Dim numbers As Integer() = {-2, -1, 0, 1, 2}
    2.  
    3. MessageBox.Show(numbers.Where(Function(n) n > 0).Min().ToString())
    Just be aware that Min will throw an exception for an empty list, so that code will choke if there are no values greater than 0.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #6

    Thread Starter
    Addicted Member Abrium's Avatar
    Join Date
    Feb 2007
    Location
    The Great State of Texas
    Posts
    205

    Re: Real quick array.min question

    Hey thanks JM.
    Abrium
    Asking the beginners questions so you don't have to!
    If by chance hell actually froze over and I some how helped you... Please rate.

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