# How to get the max values

#### psevet

##### Member
Licensed User
Hello,

I'm stuck on a problem regarding comparison :

in a edittext I enter a value, eg 10
x=1.5
z= 0.5

I want my program to calculate (value1 * x) + (value2 * z) in a loop :

for i=1 to 20
for y= 1 to 20
temp=(i * x) + (y * z)
if temp<MyEditText.text then

Here I want to get the max value beetween the current temp and the previous one, then store the i and y values depending on this comparison in order to keep the maximum value and the corresponding i and y values at the end of both loops.

end if
next
next

This would be the way I would deal with this problem, but if I can get another solution I will take it.

Thanks for your help.

Pierre

#### Erel

##### B4X founder
Staff member
Licensed User
I think that storing the values in two additional variables is the simplest solution:
B4X:
``````Dim maxI, maxY, max As Float
x=1.5
z= 0.5

for i=1 to 20
for y= 1 to 20
temp=(i * x) + (y * z)
if temp<MyEditText.text AND temp > max then
max = temp
maxI = i
maxY = y
end if
next
next``````

#### psevet

##### Member
Licensed User
Thank you very much Erel :sign0060:

You're the man !

Hope that Basic4Android makes you rich !

Cheers.

Pierre

### Similar Threads

Replies
10
Views
382
Replies
1
Views
523
Replies
2
Views
8K
Android Code Snippet RoundSlider Min/Max Values
Replies
1
Views
1K
Replies
93
Views
125K