473,386 Members | 1,715 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,386 software developers and data experts.

how to find max value

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
Nov 20 '05 #1
9 8449

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

skech wrote:
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
Nov 20 '05 #2
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

Nov 20 '05 #3
Cor
Hi Herfried,

Only typed I said, generate I can do myself also.

I will generate it automatically...

;-)

Nov 20 '05 #4
Thanks thank thanks :))
Nov 20 '05 #5
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

Cor wrote:
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
Nov 20 '05 #6
* "Cor" <no*@non.com> scripsit:
Only typed I said, generate I can do myself also.


Do you know the algorithm I use for generating the data?

;-)))

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #7
Cor
EOT

Nov 20 '05 #8
On 22 Dec 2003 16:34:08 +0100, Herfried K. Wagner [MVP] wrote:
How to find array index number of max value ?

Won't this solution return the max *value*? I believe the OP wanted the
*index* of the max value. So shouldn't it be:

\\\
Private Function Max( _
ByVal Elements() As Integer _
) As Integer
Dim k, Element As Integer Dim i As Integer For k = 0 To UBound(Elements)
If Elements(k) > Element Then
Element = Elements(k) i = k End If
Next k Return i End Function
///



--
Chris

To send me an E-mail, remove the underscores and lunchmeat from my E-Mail
address.
Nov 20 '05 #9
Well since this thread is still going... the original question did ask for
the index and it would be important not to consider the initial maximum
value equal to zero... it should be set to the first element of the array
(all the values can be negative numbers).

So here is my solution:

Dim a() As Integer = {1, 3, 5, 15, 4, 99, 11}

Console.WriteLine(MaxIntegersIndex(a).ToString)
Console.WriteLine(MaxIntegersValue(a).ToString)
Public Function MaxIntegersIndex(ByVal a() As Integer) As Integer

MaxIntegersIndex = 0

For i As Integer = 1 To UBound(a)
If a(i) > a(MaxIntegersIndex) Then
MaxIntegersIndex = i
End If
Next

End Function

Public Function MaxIntegersValue(ByVal a() As Integer) As Integer
MaxIntegersValue = a(MaxIntegersIndex(a))
End Function
"Chris Dunaway" <dunawayc@_lunchmeat_sbcglobal.net> wrote in message
news:1w*****************************@40tude.net...
On 22 Dec 2003 16:34:08 +0100, Herfried K. Wagner [MVP] wrote:
How to find array index number of max value ?


Won't this solution return the max *value*? I believe the OP wanted the
*index* of the max value. So shouldn't it be:

\\\
Private Function Max( _
ByVal Elements() As Integer _
) As Integer
Dim k, Element As Integer

Dim i As Integer
For k = 0 To UBound(Elements)
If Elements(k) > Element Then
Element = Elements(k)

i = k
End If
Next k

Return i
End Function
///

Nov 20 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: mike | last post by:
I have an xml structure like: <data> <struct>1,8,7,30</struct> </data> and I need to develop a test that finds this node in each of these cases, something like: should find because 1 is...
7
by: pwnalwandi | last post by:
hi everyone out there can anyone give me the value of a(wn executed saperatly) initially a=5 a+=(a++)+(++a) a-=(--a)-(a--) support ur answers with reasons (precedence,assoivity) thanks in...
1
by: diego | last post by:
Hi all, If I have a combo bound to as datasource, how can I search for a particular value. example i have the value 1,2,3,4 in col1 and A, B, C, D in col 2 of a datatablem and this datatable is...
1
by: ron.vdm | last post by:
Hi all. I have a SQL question I am having trouble with. We have a table, with a column that contains a code. These codes start at '00001', '00002', '00003', '00004'... and so on. If the record...
4
by: Matt Kruse | last post by:
According to standards, if an option is selected and it has no VALUE attribute, the contents of the option tag is to be submitted. So: <select name="sel"> <option selected>Value</option>...
3
by: shapper | last post by:
Hello, I have 2 data sets: dsLevels and dsLevelsSubscribed. And I created this loop: For Each row As DataRow In dsLevels.Tables(0).Rows ??? row("LevelName") Next row
3
by: cmay | last post by:
I have a situation where I need a collection, where I can find the VALUE (e.g. customer name) by it's key (ID value), AND also find the ID value by the customer name. Is there anything that does...
6
by: nickvans | last post by:
Hi All. I have a form with several text boxes for a user to enter part numbers and quantities: partnum1, partnum2, partnum3 / qty1, qty2, qty3 etc. I have a loop set up in VBA which goes...
3
by: Friebo | last post by:
Hi, I'm having troubles with the following: I have 2 tables, Candidates and Attachments. In the Candidate there is a column called email1. In the Attachment table, there is a column called...
0
by: shapper | last post by:
Hello, I created the following SelectList: var targets = new Dictionary<string, string>(); targets.Add("New Window", "_blank"); targets.Add("SameWindow", "_self"); viewData.Targets = new...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...

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.