Jump to content

How to get and store the largest number from list into a variable - (Moved)


Recommended Posts

Hi, 

How can I get the largest number to be the first number in a calculation? I did the below code but the largest number doesn't store in the $ aExtract variable. I need always a positive number from the calculation (the largest number be the first in the calculation). Can you help me with that? Thank you.

$N1 = 33
$N2 = 45

Local $numberSort [2] = [$N1 , $N2]

_ArraySort($numberSort, 1)
_ArrayDisplay($numberSort, "Sort Descending", Default, 1)
Local $aExtract = _ArrayExtract($numberSort, 0, 0, 0)
_ArrayDisplay($aExtract, "Row 1 cols 1")

$minus = $N1 - $N2

 

Edited by ramin92003
Link to comment
Share on other sites

Maybe this?

#include <array.au3>

$N1 = 33
$N2 = 45

Local $numberSort [2] = [$N1 , $N2]

_ArraySort($numberSort, 1)
_ArrayDisplay($numberSort, "Sort Descending", Default, 1)
Local $aExtract = _ArrayExtract($numberSort, 0, 0, 0)
_ArrayDisplay($aExtract, "Row 1 cols 1")

$minus = $numberSort [0] - $numberSort [1]

 

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

In your script you basically answered your own question. 

Have a look at the last part of your script:
 

$minus = $numberSort [0] - $numberSort [1]

Here you are using an equation to minus the two array results.
Therefore, by using either of them, you can add this to your message box like so...

#include <array.au3>

$N1 = 33
$N2 = 45

Local $numberSort [2] = [$N1 , $N2]

_ArraySort($numberSort, 1)
MsgBox(-1, "Title Goes Here",$numberSort [0] ,5) ;Add five seconds time out
Local $aExtract = _ArrayExtract($numberSort, 0, 0, 0)
MsgBox(-1, "Title Goes Here",$numberSort [1] ,5) ;Add five seconds time out
$minus = $numberSort [0] - $numberSort [1]
MsgBox(-1, "Title Goes Here",$minus ,5) ;Add five seconds time out

 

Kind Regards
Skeletor

"Coffee: my defense against going postal."

Microsoft Office Splash Screen | Basic Notepad Program (Beginner) | Transparent Splash Screen | Full Screen UI

Link to comment
Share on other sites

  • Moderators

Moved to the appropriate forum, as the Developer General Discussion forum very clearly states:

Quote

General development and scripting discussions. If it's super geeky and you don't know where to put it - it's probably here.


Do not create AutoIt-related topics here, use AutoIt General Help and Support.

Moderation Team

Edited by JLogan3o13

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

also no need to sort in this case, as there are functions that return the highest and lowest value

#include<array.au3>

Local $numberSort [2] = [33 , 45]

msgbox(0, ' ' , _ArrayMax($numberSort) - _ArrayMin($numberSort))

 

 

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...