By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,068 Members | 874 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,068 IT Pros & Developers. It's quick & easy.

how do I get the highest value from an array

P: n/a
Jan
Hi there,

Is there a fast way to get the highest value from an array?

I've got the array strStorage(intCounter)

I tried something but it all and's to nothing

If someone good helpme, TIA
Nov 21 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
Jan,

It is with arrays .Length and with collections .Count

However, try to avoid the base Array class direct. Not in connection with
the previous, as a strange behaviour has that class in Visual Basic Net the
effect that this class (and everything that derives from it) creates one
item more than you tell that it has to creat.e
\\\
dim a(10) as string
///
Creates 11 strings. Therefore when I am using this class and want 10 items I
do
\\\
dim a(9) as string
dim b as integer = a.length ' gives 10
///
Better is in my opinion, when your want to use array has not to use those
fixed ones however the Arraylist.
\\\
dim ar as arraylist.
///

It is dynamic however is it as well using the .length to get the items in it

I hope this helps,

Cor
Nov 21 '05 #2

P: n/a
Hi There,

When you say the highest value from the array, this could mean more than one
thing.

1.) You could be asking for the highest numerical value from all values in
the array

2.) You could be asking for then top index value or ( ArrayName.Length ) of
the array.

3.) In an array, you could be asking for the value with the highest index.
For example, if you set up an array of strings, if could be the highest
non-empty string., assuming elements were filled contiguously from 0 up.

Can you be more specific, or do my questions provide you with some sort of
answer ?

HTH
--
OHM ( Terry Burns )

http://TrainingOn.net

"Jan" <ca*****@planet.nl> wrote in message
news:1k*****************************@40tude.net...
Hi there,

Is there a fast way to get the highest value from an array?

I've got the array strStorage(intCounter)

I tried something but it all and's to nothing

If someone good helpme, TIA

Nov 21 '05 #3

P: n/a
"Jan" <ca*****@planet.nl> schrieb:
Is there a fast way to get the highest value from an array?

I've got the array strStorage(intCounter)


\\\
MsgBox(CStr(GetMax(1, 3, 6, 2, -5, 99, 2, 3)))
MsgBox(CStr(GetMax(New Integer() {1, 3, 6, 2, -5, 99, 2, 3})))
..
..
..
Private Function GetMax( _
ByVal ParamArray Items() As Integer _
) As Integer
GetMax = Integer.MinValue
For Each Item As Integer In Items
If Item > GetMax Then
GetMax = Item
End If
Next Item
End Function
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
Nov 21 '05 #4

P: n/a
Jan
On Sun, 13 Mar 2005 19:20:19 -0000, OHM ( Terry Burns ) wrote:
Hi There,

When you say the highest value from the array, this could mean more than one
thing.

1.) You could be asking for the highest numerical value from all values in
the array

2.) You could be asking for then top index value or ( ArrayName.Length ) of
the array.

3.) In an array, you could be asking for the value with the highest index.
For example, if you set up an array of strings, if could be the highest
non-empty string., assuming elements were filled contiguously from 0 up.

Can you be more specific, or do my questions provide you with some sort of
answer ?

HTH


youre write about that.

i ment the first option in your list.
so, I want the highest numerical value from all values in the array!

Sorry, about the confusion

Jan
Nov 21 '05 #5

P: n/a
Jan,

The method I would use.

http://msdn.microsoft.com/library/de...sorttopic1.asp

Cor
Nov 21 '05 #6

P: n/a
If this is what the OP is looking for then I would suggest that they may
consider implementing a class for this functionality which may set a highest
value property each time an element is set. This way one can be sure to
retreive it in the fastest time possible, rather than iterating through all
the elements.

This of course could be counter productive as it adds more processing time
to setting the elements in the first place, its a matter of judging which
operation is done most frequently, the search or the setting ? Some
impirical data may be collected in order to assess the impact or both
methods and choose whichever is most appropriate for this need.

HTH

--
OHM ( Terry Burns )

http://TrainingOn.net


"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:OA**************@TK2MSFTNGP12.phx.gbl...
"Jan" <ca*****@planet.nl> schrieb:
Is there a fast way to get the highest value from an array?

I've got the array strStorage(intCounter)


\\\
MsgBox(CStr(GetMax(1, 3, 6, 2, -5, 99, 2, 3)))
MsgBox(CStr(GetMax(New Integer() {1, 3, 6, 2, -5, 99, 2, 3})))
.
.
.
Private Function GetMax( _
ByVal ParamArray Items() As Integer _
) As Integer
GetMax = Integer.MinValue
For Each Item As Integer In Items
If Item > GetMax Then
GetMax = Item
End If
Next Item
End Function
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #7

P: n/a
See my other reply to HW in this thread .

HTH

--
OHM ( Terry Burns )

http://TrainingOn.net

"Jan" <ca*****@planet.nl> wrote in message
news:d0****************************@40tude.net...
On Sun, 13 Mar 2005 19:20:19 -0000, OHM ( Terry Burns ) wrote:
Hi There,

When you say the highest value from the array, this could mean more than
one
thing.

1.) You could be asking for the highest numerical value from all values
in
the array

2.) You could be asking for then top index value or ( ArrayName.Length )
of
the array.

3.) In an array, you could be asking for the value with the highest
index.
For example, if you set up an array of strings, if could be the highest
non-empty string., assuming elements were filled contiguously from 0 up.

Can you be more specific, or do my questions provide you with some sort
of
answer ?

HTH


youre write about that.

i ment the first option in your list.
so, I want the highest numerical value from all values in the array!

Sorry, about the confusion

Jan

Nov 21 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.