# how to know what number is bigger or the smaller

## Recommended Posts

I've "developed" a simple code that it lets you know in a simple array (1 dimension) what of the numbers is the bigger or the smaller

i know about the function _Max or _Min, but it only let you put 2 numbers

this is the code:

```\$numbers = 5
dim \$number[\$numbers]

\$number[0] = 4
\$number[1] = 6
\$number[2] = 2
\$number[3] = 8
\$number[4] = 3

\$x = 0
\$j = 1
Do
If \$number[\$x] > \$number[\$x + \$j] Then
\$j = \$j + 1
Else
\$x = \$x + \$j
\$j = 1
EndIf
until \$x + \$j >= \$number

MsgBox(0, "", "the bigger number is: " & \$number[\$x])

\$x = 0
\$j = 1
Do
If \$number[\$x] < \$number[\$x + \$j] Then
\$j = \$j + 1
Else
\$x = \$x + \$j
\$j = 1
EndIf
until \$x + \$j >= \$number

MsgBox(0, "", "the smaller number is: " & \$number[\$x])```

i'm sorry if I don't talk good english (i'm spanish)

olivarra1

PD: is this useful? ^^

Edited by olivarra1

##### Share on other sites

Cool subject... Unfortunately not working for me... Getting the following errors..

>C:\Program Files\AutoIt3\SciTE\..\au3check.exe "C:\0000 - Files\Number Bigger or Smaller.au3"

C:\XX0000 - Files\Number Bigger or Smaller.au3(29,21) : WARNING: \$num: possibly used before declaration.

until \$x + \$j = \$num

~~~~~~~~~~~~~~~~~~~~^

C:\XX0000 - Files\Number Bigger or Smaller.au3(29,21) : ERROR: \$num: undeclared global variable.

until \$x + \$j = \$num

~~~~~~~~~~~~~~~~~~~~^

C:\XX0000 - Files\Number Bigger or Smaller.au3 - 1 error(s), 1 warning(s)

>Exit code: 2 Time: 0.222

##### Share on other sites

Don't argue with an idiot; people watching may not be able to tell the difference.

##### Share on other sites

Cool subject... Unfortunately not working for me... Getting the following errors..

>C:\Program Files\AutoIt3\SciTE\..\au3check.exe "C:\0000 - Files\Number Bigger or Smaller.au3"

C:\XX0000 - Files\Number Bigger or Smaller.au3(29,21) : WARNING: \$num: possibly used before declaration.

until \$x + \$j = \$num

~~~~~~~~~~~~~~~~~~~~^

C:\XX0000 - Files\Number Bigger or Smaller.au3(29,21) : ERROR: \$num: undeclared global variable.

until \$x + \$j = \$num

~~~~~~~~~~~~~~~~~~~~^

C:\XX0000 - Files\Number Bigger or Smaller.au3 - 1 error(s), 1 warning(s)

>Exit code: 2 Time: 0.222

Fixed

mhhh but isn't this a very long script?

olivarra1

##### Share on other sites

Fixed

mhhh but isn't this a very long script?

olivarra1

Maybe, I wrote it about 2 years ago, can probably be shortened if someone wants to take the time to.

Don't argue with an idiot; people watching may not be able to tell the difference.

##### Share on other sites

I've "developed" a simple code that it lets you know in a simple array (1 dimension) what of the numbers is the bigger or the smaller

i know about the function _Max or _Min, but it only let you put 2 numbers

this is the code:

```\$numbers = 5
dim \$number[\$numbers]

\$number[0] = 4
\$number[1] = 6
\$number[2] = 2
\$number[3] = 8
\$number[4] = 3

\$x = 0
\$j = 1
Do
If \$number[\$x] > \$number[\$x + \$j] Then
\$j = \$j + 1
Else
\$x = \$x + \$j
\$j = 1
EndIf
until \$x + \$j >= \$number

MsgBox(0, "", "the bigger number is: " & \$number[\$x])

\$x = 0
\$j = 1
Do
If \$number[\$x] < \$number[\$x + \$j] Then
\$j = \$j + 1
Else
\$x = \$x + \$j
\$j = 1
EndIf
until \$x + \$j >= \$number

MsgBox(0, "", "the smaller number is: " & \$number[\$x])```

i'm sorry if I don't talk good english (i'm spanish)

olivarra1

PD: is this useful? ^^

If you change

until \$x + \$j >= \$number

to

until \$x + \$j >= \$numbers

in both places it's used then your function will work correctly.

You can simplify initialising an array like this

`Dim \$number[5] = [4,6,2,8,3]`

and for the last element you can use Ubound(\$number) - 1 so you would have

until \$x + \$j >= Ubound(\$number) - 1

Although that is more complicated it means you can apply your code to an array with any number of elements greater than 1.

Edited by martin

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

##### Share on other sites

works with 1 or 2 arrays (1 dimensional)

```#include <Array.au3>
#include <Misc.au3>

Local \$Array1[5] = [3, 2, 8, 5, 10]
Local \$Array2[3] = ["02", "1", "20"]
Local \$Array3[4] = ["3", "02", "-1", "11"]
Local \$Max, \$Min

\$Max = _MinMaxa(\$Array1, 1)
If Not @error Then
ConsoleWrite('@@ Debug(1) :\$Max = ' & \$Max & @LF)
Else
ConsoleWrite('@@ Debug(1) :Error = ' & @error & @LF)
EndIf

\$Max = _MinMaxa(\$Array2, 1)
If Not @error Then
ConsoleWrite('@@ Debug(2) :\$Max = ' & \$Max & @LF)
Else
ConsoleWrite('@@ Debug(2) :Error = ' & @error & @LF)
EndIf

\$Max = _MinMaxa(\$Array3, 1, \$Array1)
If Not @error Then
ConsoleWrite('@@ Debug(3) :\$Max = ' & \$Max & @LF)
Else
ConsoleWrite('@@ Debug(3) :Error = ' & @error & @LF)
EndIf

\$Min = _MinMaxa(\$Array1)
If Not @error Then
ConsoleWrite('@@ Debug(4) :\$Min = ' & \$Min & @LF)
Else
ConsoleWrite('@@ Debug(4) :Error = ' & @error & @LF)
EndIf

\$Min = _MinMaxa(\$Array2)
If Not @error Then
ConsoleWrite('@@ Debug(5) :\$Min = ' & \$Min & @LF)
Else
ConsoleWrite('@@ Debug(5) :Error = ' & @error & @LF)
EndIf

\$Min = _MinMaxa(\$Array1, 0, \$Array3)
If Not @error Then
ConsoleWrite('@@ Debug(6) :\$Min = ' & \$Min & @LF)
Else
ConsoleWrite('@@ Debug(6) :Error = ' & @error & @LF)
EndIf

; return min or max number from 1 or 2 arrays
Func _MinMaxa(ByRef \$a_nums01, \$MaxFlag = 0, \$a_nums02 = 0)
Local \$vnum02
If Not IsArray(\$a_nums01) Then Return SetError(1, 0, 0)
If @NumParams = 3 Then
If Not IsArray(\$a_nums02) Then Return SetError(3, 0, 0)
\$vnum02 = _MinMaxa(\$a_nums02, \$MaxFlag)
If @error Then Return SetError(@error, 0, 0)
EndIf
;
For \$idx = 0 To UBound(\$a_nums01) - 1
If StringIsFloat(\$a_nums01[\$idx]) Or StringIsInt(\$a_nums01[\$idx]) Then
\$a_nums01[\$idx] = Number(\$a_nums01[\$idx])
Else
Return SetError(2, 0, 0)
EndIf
Next
_ArraySort(\$a_nums01, \$MaxFlag)
If @NumParams = 3 Then
If \$MaxFlag Then
Return _Iif(\$a_nums01[0] > \$vnum02, \$a_nums01[0], \$vnum02)
Else
Return _Iif(\$a_nums01[0] < \$vnum02, \$a_nums01[0], \$vnum02)
EndIf
EndIf
Return \$a_nums01[0]
EndFunc  ;==>_MinMaxa```
Edited by GaryFrost

Don't argue with an idiot; people watching may not be able to tell the difference.

## Create an account

Register a new account

×

• Wiki

• Back

• Git