PC Review


Reply
Thread Tools Rate Thread

how do I get the highest value from an array

 
 
Jan
Guest
Posts: n/a
 
      13th Mar 2005
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
 
Reply With Quote
 
 
 
 
Cor Ligthert
Guest
Posts: n/a
 
      13th Mar 2005
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


 
Reply With Quote
 
OHM \( Terry Burns \)
Guest
Posts: n/a
 
      13th Mar 2005
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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



 
Reply With Quote
 
Herfried K. Wagner [MVP]
Guest
Posts: n/a
 
      13th Mar 2005
"Jan" <(E-Mail Removed)> 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/>
 
Reply With Quote
 
Jan
Guest
Posts: n/a
 
      13th Mar 2005
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
 
Reply With Quote
 
Cor Ligthert
Guest
Posts: n/a
 
      13th Mar 2005
Jan,

The method I would use.

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

Cor


 
Reply With Quote
 
OHM \( Terry Burns \)
Guest
Posts: n/a
 
      13th Mar 2005
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]" <hirf-spam-me-(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> "Jan" <(E-Mail Removed)> 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/>



 
Reply With Quote
 
OHM \( Terry Burns \)
Guest
Posts: n/a
 
      13th Mar 2005
See my other reply to HW in this thread .

HTH

--
OHM ( Terry Burns )

http://TrainingOn.net



"Jan" <(E-Mail Removed)> wrote in message
news:d0r23vc453oy$.(E-Mail Removed)...
> 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



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Trying to return an array of numbers and choose the highest meghnaubhan@gmail.com Microsoft Excel Discussion 33 13th Feb 2008 12:50 PM
highest value in a an array =?Utf-8?B?cm9kY2hhcg==?= Microsoft C# .NET 3 4th Apr 2007 08:42 PM
Selecting next to highest number in an array? robotman@gmail.com Microsoft Excel Programming 2 8th Nov 2006 03:34 AM
Locating lowest/highest cell value in an array Paul Rampenthal Microsoft Excel Programming 4 16th Apr 2004 04:28 PM
Testing For Highest Number in an array WStoreyII Microsoft VB .NET 8 14th Mar 2004 06:58 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:19 PM.