Android Question elegant coding

DPaul

Active Member
Licensed User
Longtime User
Hi,

I am looking for elegant way to code this:

At the end of a series of for nexts and select cases, i end up with 16 different varables,
all with different names, all integers between 0 and 100.

i need to know what is the largest number (value), doesn't matter if there are more than one
with the same max. value.

What is the simplest (shortest) route to choose ? Lists ?
I dont think there is a "max" function somewhere.

thx,
Paul
 

DonManfred

Expert
Licensed User
Longtime User
ise a List, add all Values. Sort the list DESCending. The first item in the List is the Max Value.

You also can use

Max (Number1 As Double, Number2 As Double) As Double

to check each value...

B4X:
dim maxval as double = 0
'
' Check each value you have against max
maxval = max(maxval, yourvalue)

At the end you should have maxval containing the maximun value...
 
Last edited:
Upvote 0

udg

Expert
Licensed User
Longtime User
You could even dim a global var (e.g named maxvalue) and update it out of every for/next loop or select statement if the just computed value is greater than current value of that var.

I don't think it will make a big difference on only 16 values (an IF test after each loop versus an assignment to a List and a List sorting at the end). A few bytes less of RAm footprint, non so many CPU cycles difference.

Considering hundreds or thousands of values it could be something to explore.

udg
 
Upvote 0

udg

Expert
Licensed User
Longtime User
Upvote 0
Top