Finding maximum number - Forum

Forum Navigation
You need to log in to create posts and topics.

Finding maximum number

I was used the following code for finding the maximum number at first version of Visualneo web that time it was work properly but with current version it does not work properly:

https://tinyurl.com/y3mxam6z

StrParse "[input]" "," [x]
ArrayLen [x] [len]

.finding maximum of array
setvar [max] [x(0)]
SetVar [length] [len]-1
.......................
Loop 1 [length] [i]
If [max] < [x([i])]
setvar [max] [x([i])]
Endif
endloop

setvar [max] [max]

what is wrong here?

salam asmat
agar emkan dare email khodet ro be man bedeh

mitoonim ba ham hamkari konim

email man ine abedini1339@gmail.com

eradatmandam

farhad

@asmat, you are comparing strings, not numbers.
Use this instead:

StrParse "[input]" "," [x]
ArrayLen [x] [len]

.finding maximum of array
setvar [max] [x(0)]
SetVar [length] [len]-1
.......................
Loop 1 [length] [i]

Math "[x([i])]" 0 [x([i])]

If [max] < [x([i])]
setvar [max] [x([i])]
Endif
endloop

setvar [max] [max]

The added Math command will convert any string to a number. This way you can even parse math calculations like this:

7,5,4+(2*3),44,55

Regards.

asmat has reacted to this post.
asmat