Results 1 to 18 of 18

Thread: [RESOLVED] [2005] Extracting maximum and Minimum Value from a set of values

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2005
    Posts
    449

    Resolved [RESOLVED] [2005] Extracting maximum and Minimum Value from a set of values

    I have a function that return 10 variables;

    Is it possible to extract max and min values of these variables

    a=5
    b=6
    c=8
    d=4
    e=3
    f=2
    g=1
    h=9 etc
    Max val = 9
    Min Val = 1
    Last edited by surya; Jul 13th, 2007 at 02:47 AM.

  2. #2
    Frenzied Member stimbo's Avatar
    Join Date
    Jun 2006
    Location
    UK
    Posts
    1,739

    Re: [2005] Extracting maximum and Minimum Value from a set of values

    Could you add them to an array or List (of Integer)?

    Then you would simply to a sort and get the lowest and uppermost bounds.
    Stim

    Free VB.NET Book Chapter
    Visual Basic 2005 Cookbook Sample Chapter

  3. #3
    New Member
    Join Date
    Jul 2007
    Posts
    3

    Re: [2005] Extracting maximum and Minimum Value from a set of values

    i don't know much. But i can give you an idea.
    Use an array instead of so much variables
    then sort it by using ..................... arrayname.sort()
    Use it's first and last value for minimum and maximum value.

  4. #4
    Hyperactive Member NPassero's Avatar
    Join Date
    May 2007
    Location
    NJ
    Posts
    272

    Re: [2005] Extracting maximum and Minimum Value from a set of values

    vb.net Code:
    1. Dim myArray() as Integer = { 5, 6, 8, 4, 3, 2, 1, 9 }
    2. Dim Max as Integer
    3. Dim Min as Integer
    4.  
    5. Array.Sort(myArray)
    6.  
    7. Max = myArray(myArray.length - 1)
    8. Min = myArray(0)

    If you have any questions about Arrays just ask.

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2005
    Posts
    449

    Re: [2005] Extracting maximum and Minimum Value from a set of values

    Hello Passero,
    Many thanks for your response.

    As these values are available in a variables,
    How do I append them to myarray()?

  6. #6
    Hyperactive Member Troy Lundin's Avatar
    Join Date
    May 2006
    Posts
    489

    Re: [2005] Extracting maximum and Minimum Value from a set of values

    How do I append them to myarray()?
    Just use a List(Of Integer) instead like mentioned above.

    Dim list As List(Of Integer)
    list.Add(a)
    etc...
    Prefix has no suffix, but suffix has a prefix.

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2005
    Posts
    449

    Re: [2005] Extracting maximum and Minimum Value from a set of values

    Quote Originally Posted by Troy Lundin
    Just use a List(Of Integer) instead like mentioned above.

    Dim list As List(Of Integer)
    list.Add(a)
    etc...
    Below syntax seems to be wrong, can you please check?

    Code:
    myArray.add(x)
    myArray.add(y)
    myArray.add(z)
    Last edited by surya; Jul 12th, 2007 at 03:25 AM.

  8. #8
    Frenzied Member stimbo's Avatar
    Join Date
    Jun 2006
    Location
    UK
    Posts
    1,739

    Re: [2005] Extracting maximum and Minimum Value from a set of values

    2 Code:
    1. Dim x As Integer = 5
    2. Dim u As Integer = 3
    3. Dim s As Integer = 9
    4.  
    5. Dim myNums As New List(Of Integer)
    6.  
    7.         myNums.Add(x)
    8.         myNums.Add(u)
    9.         myNums.Add(s)
    10.  
    11.         myNums.Sort()
    12.  
    13.         MessageBox.Show(myNums(0).ToString)  'Lowest
    Stim

    Free VB.NET Book Chapter
    Visual Basic 2005 Cookbook Sample Chapter

  9. #9

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2005
    Posts
    449

    Re: [2005] Extracting maximum and Minimum Value from a set of values

    thanks a lot stim,

    I am trying to extract the max value using
    Code:
    Max = myArray(myArray.length - 1)
    I am getting error.. Can you please correct me...

  10. #10
    Frenzied Member stimbo's Avatar
    Join Date
    Jun 2006
    Location
    UK
    Posts
    1,739

    Re: [2005] Extracting maximum and Minimum Value from a set of values

    As long as myArray is a List (of Integer) rather than an array it would be:

    2 Code:
    1. Max = myArray(myArray.Count - 1)
    Stim

    Free VB.NET Book Chapter
    Visual Basic 2005 Cookbook Sample Chapter

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

    Re: [2005] Extracting maximum and Minimum Value from a set of values

    May I make two suggestions?

    1. If something is not an array then don't name it "myArray".
    2. Don't post that you get an error without posting details of the error, most specifically the error message.
    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

  12. #12

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2005
    Posts
    449

    Re: [2005] Extracting maximum and Minimum Value from a set of values

    Many thanks Stim & stimbo

    I was using Max = myArray(myArray.length - 1)

    instead of Max = myArray(myArray.Count - 1)
    Thanks a lot all of you...

    thanks jmc for the suggestion

  13. #13

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2005
    Posts
    449

    Re:[2005] Extracting maximum and Minimum Value from a set of values

    Hi,
    One last question..
    Is it possible to remove the duplicates in the string...

    thanks
    Last edited by surya; Jul 13th, 2007 at 02:46 AM.

  14. #14
    Hyperactive Member NPassero's Avatar
    Join Date
    May 2007
    Location
    NJ
    Posts
    272

    Re: [2005] Extracting maximum and Minimum Value from a set of values

    vb.net Code:
    1. Dim myString As String = "hello"
    2.       Dim i, length As Integer
    3.       Dim c As Char
    4.  
    5.       length = myString.Length - 1
    6.  
    7.       For i = 0 To length
    8.          If i > length Then
    9.             Exit For
    10.          End If
    11.          c = myString(i)
    12.  
    13.          If myString.IndexOf(c, i + 1) > -1 Then
    14.             myString = myString.Remove(i, 1)
    15.          End If
    16.  
    17.          length = myString.Length - 1
    18.       Next
    19.  
    20.     ' Will result with myString = "helo"

    thats in one string. has nothing to do with arrays or lists.

  15. #15

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2005
    Posts
    449

    Re: [2005] Extracting maximum and Minimum Value from a set of values

    Many thanks for your prompt response passero;

    I am getting an error, when I use the length attribute; can you please have a look..

    Code:
    
    Dim Load_String As String = ""
            Dim ArrLoadCases As New List(Of Double)
    
            ArrLoadCases.Add(MaxVal_PS_BR_LoadCombo)
            ArrLoadCases.Add(MaxVal_PT_CR_LoadCombo)
            ArrLoadCases.Add(MaxVal_PT_TR_LoadCombo)
            ArrLoadCases.Add(MaxVal_AB_TR_LoadCombo)
            ArrLoadCases.Add(MaxVal_AB_CR_LoadCombo)
            ArrLoadCases.Add(MaxVal_AB_CbR_LoadCombo)
            ArrLoadCases.Add(Maxval_AB_ER_LoadCombo)
    
            ArrLoadCases.Sort()
    
    Dim ArrLoadCases_len As Integer
    ArrLoadCases_len = ArrLoadCases.length-1
    I am getting an error length' is not a member of 'System.Collections.Generic.List(Of Double)'

    Can you please have a look.

    Thanks

  16. #16

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2005
    Posts
    449

    Re: [2005] Extracting maximum and Minimum Value from a set of values

    Following temp values can be used for the variables below:
    Code:
    MaxVal_PS_BR_LoadCombo  = 0.50
    MaxVal_PT_CR_LoadCombo = 0.75
    MaxVal_PT_TR_LoadCombo= 0.75
    MaxVal_AB_TR_LoadCombo = 0.45
    MaxVal_AB_CR_LoadCombo = 0.65
    MaxVal_AB_CbR_LoadCombo = 0.95
    Maxval_AB_ER_LoadCombo = 0.91

  17. #17
    Hyperactive Member NPassero's Avatar
    Join Date
    May 2007
    Location
    NJ
    Posts
    272

    Re: [2005] Extracting maximum and Minimum Value from a set of values

    When using a List(Of Double) the method to get the length of items is .Count instead of .Length
    ArrayList / Lists use Count, Array's, strings etc, use Length

  18. #18

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2005
    Posts
    449

    Thumbs up Re: [2005] Extracting maximum and Minimum Value from a set of values

    Quote Originally Posted by NPassero
    When using a List(Of Double) the method to get the length of items is .Count instead of .Length
    ArrayList / Lists use Count, Array's, strings etc, use Length
    thanks a lot Passero...

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