maximum number - Forum

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

maximum number

hello

What is the easiest way to find the

Maximum number Among of several numbers?

YASIN has reacted to this post.
YASIN

سلام هموطن

این اعداد رو میخوای کجا وارد کنی ؟

یا اینکه کجا وارد شده که میخوای تشخیص بدی ؟

توی متغیره ؟ توی تکست اینتری ؟

اگر میشه یه نمونه بزار  شاید بتونم کمکت کنم


Hello fellow countryman

Where do you want to enter these numbers?

Or where is it entered that you want to recognize?

Is it in the variable? In the text entry?

If possible, give an example, maybe I can help you

سلام یاسین
بزرگترین عدد باید از بین چند متغیر انتخاب شود.

Hello @yasin
The largest number must be selected from among several variables.

Try this in a button:

SetVar [a] 12
setvar [b] 1
setvar [c] 22
setvar [d] 3
SetVar [e] 5
SetVar [numbers] "[a],[b],[c],[d],[e]"
StrParse "[numbers]" "," [myArray]
ArrayNumSort [myArray]
ArrayReverse [myArray]
setvar [max] [myArray(0)]

 

The variable [max] is the maximum

@roccocogliano

ArrayNumSort and ArrayReverse

cannot be used in neobook.
Can getarrayinfo be used?
 

sorry, I hadn't seen that it was visualneo win

then you have to loop through arrays and whenever you find a number that is bigger than the maximum found in the previous loop you replace it. in js it would be like this:

function findMax(arr) {
let max = arr[0];
for (let i = 1; i < arr.length; i++) {
if (arr[i] > max) {
max = arr[i];
}
}
return max;
}

Where arr it's the array that contain numbers

convert it to visual neo win.

@s7shanbe

Can getarrayinfo be used?

No, this command returns the item position (1st, 3rd etc.) of the numbers of the highest/lowest items with a non-null value; so, e.g. if you had 10 items, and you removed/deleted the first and last two items, this command would return 2 and 8.

But, using parts of script posted by @roccocogliano , you can still meet your requirement using just VisualNeoWin scripts ...

SetVar "[a]" "12"
setvar "[b]" "1"
setvar "[c]" "22"
setvar "[d]" "3"
SetVar "[e]" "5"
SetVar "[numbers]" "[a],[b],[c],[d],[e]"

StrParse "[numbers]" "," "[myArrayItems]" "[myArrayCount]"

SetVar "[maxNumber]" "[myArrayItems1]"

... loop through rest of items to find largest number
Loop "2" "[myArrayCount]" "[thisArrayItemNumber]"
   SetVar "[thisArrayItemValue]" "[myArrayItems[thisArrayItemNumber]]"
   If "[thisArrayItemValue]" ">" "[maxNumber]"
      SetVar "[maxNumber]" "[thisArrayItemValue]"
   EndIf
EndLoop

AlertBox "maxnumber" "[maxNumber]"

 

Vadim has reacted to this post.
Vadim