|
-
Jul 11th, 2007, 07:27 AM
#1
Thread Starter
Hyperactive Member
[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.
-
Jul 11th, 2007, 07:38 AM
#2
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.
-
Jul 11th, 2007, 07:40 AM
#3
New Member
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.
-
Jul 11th, 2007, 08:12 AM
#4
Hyperactive Member
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.
-
Jul 11th, 2007, 11:58 PM
#5
Thread Starter
Hyperactive Member
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()?
-
Jul 12th, 2007, 12:49 AM
#6
Hyperactive Member
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.
-
Jul 12th, 2007, 02:44 AM
#7
Thread Starter
Hyperactive Member
Re: [2005] Extracting maximum and Minimum Value from a set of values
 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.
-
Jul 12th, 2007, 03:36 AM
#8
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
-
Jul 12th, 2007, 03:55 AM
#9
Thread Starter
Hyperactive Member
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...
-
Jul 12th, 2007, 03:58 AM
#10
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)
-
Jul 12th, 2007, 04:03 AM
#11
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.
-
Jul 12th, 2007, 04:08 AM
#12
Thread Starter
Hyperactive Member
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
-
Jul 12th, 2007, 11:43 PM
#13
Thread Starter
Hyperactive Member
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.
-
Jul 13th, 2007, 07:10 AM
#14
Hyperactive Member
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.
-
Jul 17th, 2007, 12:42 AM
#15
Thread Starter
Hyperactive Member
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
-
Jul 17th, 2007, 01:06 AM
#16
Thread Starter
Hyperactive Member
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
-
Jul 17th, 2007, 07:06 AM
#17
Hyperactive Member
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
-
Jul 19th, 2007, 12:57 AM
#18
Thread Starter
Hyperactive Member
Re: [2005] Extracting maximum and Minimum Value from a set of values
 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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|