how to find max value

  • Thread starter Thread starter skech
  • Start date Start date
S

skech

Hi,
First Question:

My_array() as Ýnteger = ("10","120","45","75","1")

How to find array index number of max value ?

Second Question:

value = 150 / 35
value = 4,2857
How to make one number or two number after comma

Apologize for my Eng.
Thanks
 
Untested . . .
'1.)

Dim x As Integer = 0
Dim maxX as Integer = 0

For x=0 to My_Array.length-1

if ( My_Array(x) > maxX ) Then
maxX = My_Array(x)
End If

Next

'2.)

MessageBox.Show(Format(4.555, "#.##"))

Regards - OHM


Hi,
First Question:

My_array() as Ýnteger = ("10","120","45","75","1")

How to find array index number of max value ?

Second Question:

value = 150 / 35
value = 4,2857
How to make one number or two number after comma

Apologize for my Eng.
Thanks

Regards - OHM# OneHandedMan{at}BTInternet{dot}com
 
* "skech said:
My_array() as Ýnteger = ("10","120","45","75","1")

How to find array index number of max value ?

\\\
Private Function Max( _
ByVal Elements() As Integer _
) As Integer
Dim k, Element As Integer
For k = 0 To UBound(Elements)
If Elements(k) > Element Then
Element = Elements(k)
End If
Next k
Return Element
End Function
///
value = 150 / 35
value = 4,2857
How to make one number or two number after comma

'Math.Round(value, digits)'.
 
Hi Skech,

This ones I like as alternative to OHM
\\\
Dim Myarray() As Double = {10, 120, 45, 75, 1}
Array.Sort(Myarray)
MessageBox.Show(Myarray(Myarray.Length - 1)).ToString()
MessageBox.Show(Decimal.Round(CDec(150 / 35), 2).ToString)
///
'keep in mind that this rounding uses the method follows IEEE Standard 754,
section 4. This kind of rounding is sometimes called rounding to nearest, or
banker's rounding.

'0,005 = 0 0,015 = 0,02 0,0025 = 0,002 etc.

?

Cor
 
What if he doesent want his array to be sorted ?

Regards - OHM
Hi Skech,

This ones I like as alternative to OHM
\\\
Dim Myarray() As Double = {10, 120, 45, 75, 1}
Array.Sort(Myarray)
MessageBox.Show(Myarray(Myarray.Length - 1)).ToString()
MessageBox.Show(Decimal.Round(CDec(150 / 35), 2).ToString)
///
'keep in mind that this rounding uses the method follows IEEE
Standard 754, section 4. This kind of rounding is sometimes called
rounding to nearest, or banker's rounding.

'0,005 = 0 0,015 = 0,02 0,0025 = 0,002 etc.

?

Cor

Regards - OHM# OneHandedMan{at}BTInternet{dot}com
 
* "Cor said:
This ones I like as alternative to OHM
\\\
Dim Myarray() As Double = {10, 120, 45, 75, 1}
Array.Sort(Myarray)

Sorting will take at least time Theta(n log(n)), looping through the
array can be done in Theta(n).
 
Hi OHM
What if he doesent want his array to be sorted ?

Dim OrgArray() As Double = {10, 120, 45, 75, 1}
Dim myarray() As Double = OrgArray
Array.Sort(myarray)
MessageBox.Show(myarray(myarray.Length - 1)).ToString()

:-)))))

Cor
 
Hi Herfried,

Will you calculate that for us in exact hours for both of this routines,

(In a VB.net coded routine of course)

Thanks in advance

:-))))

Cor
 
Wel, I'm sorry, but this seems overly complex and I agree with Herfeid
regarding the time taken to do the sort.

;-@

Regards - OHM


Hi OHM


Dim OrgArray() As Double = {10, 120, 45, 75, 1}
Dim myarray() As Double = OrgArray
Array.Sort(myarray)
MessageBox.Show(myarray(myarray.Length - 1)).ToString()

:-)))))

Cor

Regards - OHM# OneHandedMan{at}BTInternet{dot}com
 
Hi OHM,

I was busy making that example but was sticked with that rounded question,
what is always a problem for those who rounded 0,5 to 1.

I wanted to give a nice example for roundex but could not get a real good
one, so I did not.

Normaly I do everything with a for next loop but this time I did wanted to
do it on another way.
When I was ready I saw your message, but why may I not send it them it was
in another way and very good usable for this kind of small arrays?

Very few code.

Cor
 
* "Cor said:
Will you calculate that for us in exact hours for both of this routines,

(In a VB.net coded routine of course)

How many items are you sorting? 1,000,000,000,000?

No, my answer was only a theoretical note, IMO you solution is "quick
and dirty".
 
* "Cor said:
Dim OrgArray() As Double = {10, 120, 45, 75, 1}
Dim myarray() As Double = OrgArray
Array.Sort(myarray)
MessageBox.Show(myarray(myarray.Length - 1)).ToString()

:-)))))

ROFL. I want to sort a 100 MB array...
 
Hi Herfried,

Are you again typing for it?

When you are ready with it, I will sort it for you, I thought I did made
that offer before.

(But really typed by hand, I can make a methode to check that it is not
randomly made).

:-)))

Cor
 
Hi Herfried,
No, my answer was only a theoretical note, IMO you solution is "quick
and dirty".

I did want say it is, but while writing this I became in doubt.

The sample string contains 5 items and for that kind of strings it is a nice
alternative.

The timedifference will be something between the
1/1000000000000000000 and 2/1000000000000000000 second I think

Alternatively is it in a very large population as you told not intresting
anymore to get one item, you want all the items that are equal to the max.

That is difficult with the for loop because you have all the time to build
an array when you get a new max, while the sort does that in one time.

But as I said, normaly I use the for next loop for that and I am glad you
both say that it is the best method for this.

Cor
 
Of course you can send it to them.

This is just my opinion, and as we have seen many times before on this
newsgroup, unless I am one of the chosen "three" ( which I am not ) , then
my opinion doesnt amount to much really.

:)

OHM


Hi OHM,

I was busy making that example but was sticked with that rounded
question, what is always a problem for those who rounded 0,5 to 1.

I wanted to give a nice example for roundex but could not get a real
good one, so I did not.

Normaly I do everything with a for next loop but this time I did
wanted to do it on another way.
When I was ready I saw your message, but why may I not send it them
it was in another way and very good usable for this kind of small
arrays?

Very few code.

Cor

Regards - OHM# OneHandedMan{at}BTInternet{dot}com
 
Back
Top