Jump to content
ramin92003

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

Share this post


Link to post
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

Share this post


Link to post
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

 

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites
12 hours ago, ramin92003 said:

How can I display sorted numbers in a message box instead of  _ArrayDisplay ?

_ArrayDisplay displays arrays, Msgbox displays strings 
So to display ALL the sorted numbers in a Msgbox you have to use _ArrayToString  :)

Share this post


Link to post
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))

 

 


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

Share this post


Link to post
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

  • Similar Content

    • By l3ill
      Hi Gents,
      Updating one of my older scripts here and cant get around this wall...
      I want to extract chunks from an larger array of indefinite size as smaller arrays in a loop and work with them individually and then move on to the the next "extracted array" until the original array is empty.
      The amount of elements in each extracted array will usually be different so I am using _ArraySearch to find my start and stop points and storing them as variables, which brings me to my problem.
      I want to "remove" (delete) the extracted array from the original array each time using _ArrayDelete but it doesnt seem to want me to use variables.
      Here is a reproducer:
      #include <Array.au3> Local $aArray[10] For $i = 0 To 9 $aArray[$i] = $i Next _ArrayDisplay($aArray, "Original") $i_Start = 0 $i_End = 5 Local $aExtract = _ArrayExtract($aArray, $i_Start, $i_End) _ArrayDisplay($aExtract, "Extracted Array") Local $vRange = $i_Start - $i_End _ArrayDelete($aArray, $vRange) ;==error 3 - $vRange is not a valid range string If @error Then MsgBox(0, "error =", @error) EndIf _ArrayDisplay($aArray, "After Deletion") Any suggestions would be appreciated :-)
      cya,
      Bill
       
      edit:  the error I am getting is    3 - $vRange is not a valid range string
      edit 2: BTW this doesn't work either _ArrayDelete($aArray, $i_Start - $i_End)
    • By Guy_
      If I wanna be able to "vertically rotate" (scroll up and down) 2D array rows, like...

      row 0
      row 1
      row 2

      to

      row 2
      row 0
      row 1

      etc. (both directions, where the one that disappears goes to the other end) ...

      1) Do I have to make my own function, or is there a simple trick I am missing?
      2) If I have to make my own function, would it be more or less like this one I made up?
       
      Problem here is that only "UP" is working...
      * I may be missing something very simple...? :-)
      * Why can't I seem to get the first row with _ArrayExtract($_aArray, 0, 0) somehow anyway...?
      #include <Array.au3> HotKeySet("{PGUP}", "_ArrayUp") HotKeySet("{PGDN}", "_ArrayDown") Global $aArray[3][2] = [["0 ", " car"],["1 ", " bike"],["2 ", " boat"]] ToolTip(_ArrayToString($aArray), 0,0) While 1     Sleep(100) WEnd Func _2D_ArrayScroll_vert ( $_aArray, $direction = 0 )     Local $aSplit_1, $aSplit_2     If $direction = 0 Then    ; scroll DOWN         ; get all rows except last         $aSplit_1 = _ArrayExtract($_aArray, 0, UBound($_aArray) - 2 ) ;~             MsgBox(0,"", _ArrayToString($aSplit_1))         ; get last row only         $aSplit_2 = _ArrayExtract($_aArray, UBound($_aArray) - 1, UBound($_aArray) - 1 ) ;~             MsgBox(0,"", _ArrayToString($aSplit_2))         ; $aSplit_2 = 'last row' + 'all rows except last'         _ArrayAdd($aSplit_2, $aSplit_1)         $_aArray = $aSplit_2     Else                    ; scroll UP         $aSplit_1 = _ArrayExtract($_aArray, 1, UBound($_aArray) - 1 )             MsgBox(0,"", _ArrayToString($aSplit_1)) ; PROBLEM AREA: how to get 1st row of $_aArray into $aSplit_2 ? ;~      $aSplit_2 = $_aArray[0][2]  ; doesn't work  [1][2] neither         $aSplit_2 = _ArrayExtract($_aArray, 0, 0)  ; doesn't work, other variations get the wrong row, or too many rows             MsgBox(0,"", _ArrayToString($aSplit_2))         _ArrayAdd ($aSplit_1, $aSplit_2)         $_aArray = $aSplit_1     EndIf     $aArray = $_aArray     ToolTip(_ArrayToString($aArray), 0,0) EndFunc Func _ArrayDown()     _2D_ArrayScroll_vert ( $aArray ) EndFunc Func _ArrayUp()     _2D_ArrayScroll_vert ( $aArray, -1 ) EndFunc #cs ; DOWN 0 car 1 bike 2 boat 2 boat 0 car 1 bike ; UP 0 car 1 bike 2 boat 1 bike 2 boat 0 car #ce Thanks! 
    • By Shane0000
      I am trying to get column 0 from A 2D array.
      In the below example,  (adapted from Autoit Example Script for _ArrayExtract)
      The first ArrayExtract works as expected and returns only column 1 | Start Column  = 1 End column = 1
      The Second ArrayExtract returns data from all columns. | Start Column  = 0 End column = 0
      The Third ArrayExtract works as expected and returns only Row 1 . | Start Row = 1 End Row = 1
      The Fourth ArrayExtract returns data from all Rows. | Start Row = 0 End Row = 0
      If start = 1 end = 1 returns column 1 And/ row 1  respectively why does start = 0 end = 0 return all rows/columns.
      What is the correct variables to use to extract only row 0 OR column 0?
      Thank You,
      Shane
      Edit: Added work around function for anyone who needs it, description near bottom of post.
      #include <Array.au3> Local $aArray[4][4] For $i = 0 To 3 For $j = 0 To 3 $aArray[$i][$j] = $i & $j Next Next _ArrayDisplay($aArray, "Original") Local $aExtract = _ArrayExtract($aArray, 0, 3, 1, 1) ; works as expected _ArrayDisplay($aExtract, "Row 0-3 column 1") Local $aExtract = _ArrayExtract($aArray, 0, 3, 0, 0) ; irregular results _ArrayDisplay($aExtract, "Row 0-3 column 0") Local $aExtract = _ArrayExtract($aArray, 1, 1, 1, 3); works as expected _ArrayDisplay($aExtract, "Row 1 column 1 - 3") Local $aExtract = _ArrayExtract($aArray, 0, 0, 1, 3) ; irregular results _ArrayDisplay($aExtract, "Row 0 column 1 - 3")      
      ArrayExtract.au3
    • By Shane0000
      Would one of the devs or the akin look at the post below regarding ArrayExtracts inability to extract row 0 and also column 0.
      I am unsure of how where to open a ticket. 
      If I should do this instead can some one provide a link to the ticket page.
      Thank you,
      Shane
      '?do=embed' frameborder='0' data-embedContent>>
    • By GordonFreeman
      The values are:
      eg.

      10 - 6 - 56 - 37 - 21

      And i need transform the array in:

      6 - 10 - 21 - 37 - 56

      I try but return:

      10 - 21 - 37 - 56 - 6

      Note: I need the ascending.

      That is, 6 can not be greater than 56
×
×
  • Create New...