[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
Quote:
a=5
b=6
c=8
d=4
e=3
f=2
g=1
h=9 etc
Max val = 9
Min Val = 1
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.
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.
Re: [2005] Extracting maximum and Minimum Value from a set of values
vb.net Code:
Dim myArray() as Integer = { 5, 6, 8, 4, 3, 2, 1, 9 }
Dim Max as Integer
Dim Min as Integer
Array.Sort(myArray)
Max = myArray(myArray.length - 1)
Min = myArray(0)
If you have any questions about Arrays just ask.
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()?
Re: [2005] Extracting maximum and Minimum Value from a set of values
Quote:
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...
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)
Re: [2005] Extracting maximum and Minimum Value from a set of values
2 Code:
Dim x As Integer = 5
Dim u As Integer = 3
Dim s As Integer = 9
Dim myNums As New List(Of Integer)
myNums.Add(x)
myNums.Add(u)
myNums.Add(s)
myNums.Sort()
MessageBox.Show(myNums(0).ToString) 'Lowest
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...
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:
Max = myArray(myArray.Count - 1)
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.
Re: [2005] Extracting maximum and Minimum Value from a set of values
Many thanks Stim & stimbo
Quote:
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 :)
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
Re: [2005] Extracting maximum and Minimum Value from a set of values
vb.net Code:
Dim myString As String = "hello"
Dim i, length As Integer
Dim c As Char
length = myString.Length - 1
For i = 0 To length
If i > length Then
Exit For
End If
c = myString(i)
If myString.IndexOf(c, i + 1) > -1 Then
myString = myString.Remove(i, 1)
End If
length = myString.Length - 1
Next
' Will result with myString = "helo"
thats in one string. has nothing to do with arrays or lists.
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
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
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
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...