473,406 Members | 2,894 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

how do I get the highest value from an array

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
7 3317
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
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
"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
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
Jan,

The method I would use.

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

Cor
Nov 21 '05 #6
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: shank | last post by:
How do you return the highest value in a recordset of maybe 100 records? Is it necessary to run 2 recordsets? I was hoping it was as simple as Max(), but no luck. thanks
12
by: Jozef | last post by:
Hello, Is there an easy way to determine the highest point in an array that contains a value? I'm dimensioning an array to hold up to 255 items, but if it only contains three, I don't want to...
21
by: Jaspreet | last post by:
I was working on some database application and had this small task of getting the second highes marks in a class. I was able to do that using subqueries. Just thinking what is a good way of...
6
by: Ada | last post by:
hello folks, is there a way to retrieve the highest value in the ArrayList? let say i have a value in the array: {1, 4, 15, 3, 7} it should return a value 15 as the result. i've looked at...
3
by: lostncland | last post by:
I am working on this program. The array has 10 scores. (there is more to this program.) Does the last "for" section make sense? /*Defines a global constant called N throughout the file. ...
17
by: rhitz1218 | last post by:
Hi, I'm trying to create a function that will sort a number's digits from highest to lowest. For example 1000 - will become 0001 or 1234 to 4321
3
by: =?Utf-8?B?cm9kY2hhcg==?= | last post by:
hey all, i have an int array and was just wondering if there is a way to get the highest value in the array? for instance, int myValues = new int { 0, 1, 2 } highest value is 2. thanks,
3
by: MyMarlboro | last post by:
i wonder am i make a mistake or not... use Data::Dumper; my @array= qw(1 2 3 4 5 6 8 9 2 5); my $highest=@array; foreach my $number (@array) { if (@array > $highest) { $highest = @array;
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.