Jump to content

Trouble with arrays.


Fire
 Share

Recommended Posts

Hi to all.

Have small question about arrays.

Say i have array:

#include <Array.au3>

Local $avArray[10]

$avArray[0] = "12"
$avArray[1] = "2"
$avArray[2] = "3"
$avArray[3] = "0"
$avArray[4] = "5"
$avArray[5] = "6"
$avArray[6] = "150"
$avArray[7] = "8"
$avArray[8] = "9"
$avArray[9] = "7"

MsgBox(64, "",_ArrayMin($avArray,1,0,0))
MsgBox(64, "",_ArrayMax($avArray,1,0,9))

In result i want sort its like:

0,2,3,5,6,7,8,9,12,150

also i try _ArraySort,and searched about this in forum and i find:

http://www.autoitscript.com/forum/index.php?showtopic=94799&st=0&p=703473&hl=compare%20arrays&fromsearch=1&#entry703473

But unable to do like above.

Any tips appreciated.

P.S I know i will try it under loop like:

for example:

for $i=3 to 10
    MsgBox(64, "",_ArrayMin($avArray,1,$i,0))

If $i=10 Then
    ExitLoop

EndIf
Next
      Exit

But in here too i cannot figure it out correctly.

Yet i try this too like:

#include <Array.au3>

Local $avArray = StringSplit("4,2,0", ",")    

MsgBox(64,"Min 1 n","Fist min ==> " & _ArrayMin($avArray, 1,1, 0))       
MsgBox(64,"Min 2 ","Second min => " & "  " & _ArrayMin($avArray,1,1, 2))  
MsgBox(64, "Maks","Max =>  " &  _ArrayMax($avArray,1,1,0))     
exit

But what if the the numders here over 10k?How to compare it automatically and sort of all

like below:

0,2,3,5,6,7,8,9,12,150 and etc.

I need really your tips about this.

Thanks again to all.

[size="5"] [/size]
Link to comment
Share on other sites

  • Developers

Looks like you are sorting strings, not numbers!

Convert the strings to numbers before sorting.

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

  • Moderators

Sh3llC043r,

You need to decide whether you want to sort number or strings. Go and look at the $iCompNumeric parameter for _ArrayMax and _ArrayMin - that might help. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

I`m sorry again for stupid question but i`m trying to receive result which i want but no success again ;)

Already I tear hair as I can not receive correct result.

I will forgive from you tell where my errors in this case:(Plizz i just need one simple and i think this is enough for me for handle correctly it in future)

#include <Array.au3>

Local $avArray[3]

$avArray[0] = "12"
$avArray[1] = "0"
$avArray[2]="2"


;MsgBox(64, "dd",UBound($avArray,1)) ;3 dimension this is right.

for $i =1 To UBound($avArray,1) ;3
    MsgBox(64, "",_ArrayMin($avArray,1,$i,UBound($avArray,1)))
    MsgBox(64, "",_ArrayMax($avArray,1,$i,0))


    if $i=3 Then
        ExitLoop
    Else
        EndIf


Next
[size="5"] [/size]
Link to comment
Share on other sites

  • Moderators

Sh3llC043r,

Where did the loop come from? ;)

All you need is:

#include <Array.au3>

Local $avArray[3]

$avArray[0] = "12"  ; These are strings
$avArray[1] = "0"
$avArray[2] = "2"

; So we need to tell the function to compare as numbers by setting the $iCompNumeric parameter to 1
MsgBox(64, "Min Number", _ArrayMin($avArray, 1))
MsgBox(64, "Max Number", _ArrayMax($avArray, 1))

; Compare the results here where we compare as strings
MsgBox(64, "Min String", _ArrayMin($avArray))
MsgBox(64, "Max String", _ArrayMax($avArray))

I hope that is clear. :evil:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Hi,

Dear Melba23.

Thank you very much for your help again.

But here is my simple script and i have logical wrong programm.

#include <GUIConstants.au3>
#include <Array.au3>
$Form1 = GUICreate("", 205, 322, 283, 156)
$Input1 = GUICtrlCreateInput("", 48, 64, 113, 21)
$Input2 = GUICtrlCreateInput("", 48, 128, 113, 21)
$Input3 = GUICtrlCreateInput("", 48, 192, 113, 21)
$Button1 = GUICtrlCreateButton("OK", 64, 256, 81, 25, 0)
$Label1 = GUICtrlCreateLabel("              ENTER DIGITS", 16, 8, 122, 17)
GUISetState(@SW_SHOW)


While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            Local $avArray[3]
            $avArray[0] =GUICtrlRead($Input1)
            $avArray[1]  = GUICtrlRead($Input2)
            $avArray[2] =GUICtrlRead($Input3)

            MsgBox(64, "Min Number", _ArrayMin($avArray, 1))
            MsgBox(64, "Min Number 1", _ArrayMin($avArray, 1,2,2))
            MsgBox(64, "Max Number",_ArrayMax($avArray,1))



    EndSwitch
WEnd

For example:

Say i enter :

-----------------------------------------
| INPUTBOX1      |      1         |
-----------------------------------------
| INPUTBOX2      |     152      |
-----------------------------------------
| NPUTBOX3      |       3         |
-----------------------------------------

Result in this case is correct for me.

__________________________________________________________________________

But when i enter:

-----------------------------------------
| INPUTBOX1      |   5000         |
-----------------------------------------
| INPUTBOX2      |     0         |
-----------------------------------------
| INPUTBOX3      | 9000000    |
-----------------------------------------

result is this case is logical wrong 66% .

I want to know how to prevent it and get logical correct result(100%) in this case? or write right code?

I know 100% in my this code arrays used by static logical prinsipe.( there must be some dynamic "handle" method(s) for array index)

But how to do this correct logical in dynamyc prinsipe?

some tips,hints will be appreciated.

Thank you very-very much again.

[size="5"] [/size]
Link to comment
Share on other sites

  • Moderators

Sh3llC043r,

Your code is doing exactly what you have asked it to do:

First MsgBox - shows the lowest number in the array. Using your examples I get: 1 & 0 - which is what I would expect.

Third MsgBox - shows the highest number in the array. Your examples give: 152 & 9000000 - again what I would expect.

But the syntax of the Second MsgBox only looks at the contents of element [2] of the array - so it will only ever return the value of that element - which it does: 3 & 9000000.

What do you want this second MsgBox to display? ;)

As to the "dynamic" arrays, take a look at this:

#include <GUIConstantsEx.au3>
#include <Array.au3>

Global $avArray[3], $Input[UBound($avArray)]

$Form1 = GUICreate("", 205, 322, 283, 156)
$Input[0] = GUICtrlCreateInput("", 48, 64, 113, 21)
$Input[1] = GUICtrlCreateInput("", 48, 128, 113, 21)
$Input[2] = GUICtrlCreateInput("", 48, 192, 113, 21)
$Button1 = GUICtrlCreateButton("OK", 64, 256, 81, 25, 0)
$Label1 = GUICtrlCreateLabel("              ENTER DIGITS", 16, 8, 122, 17)
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            For $i = 0 To UBound($avArray) - 1
                ConsoleWrite($i & " - " & $Input[$i] & @CRLF)
                $avArray[$i] = GUICtrlRead($Input[$i])
            Next

            MsgBox(64, "Min Number in Array", _ArrayMin($avArray, 1))
            ; What does this next MsgBox do?
            ; You are only looking at the [2] element so you will only ever get the number in $Input[2]!
            MsgBox(64, "Min Number 1", _ArrayMin($avArray, 1, 2, 2))
            MsgBox(64, "Max Number in Array", _ArrayMax($avArray, 1))

    EndSwitch
WEnd

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

I agree with you Melba23.

I have changed the second msgbox and it will be display to me:1`st index of array.

Case $Button1
            Local $avArray[3]
            $avArray[0] =GUICtrlRead($Input1)
            $avArray[1]  = GUICtrlRead($Input2)
            $avArray[2] =GUICtrlRead($Input3)

            MsgBox(64, "Min Number", _ArrayMin($avArray, 1))
            MsgBox(64, "Min Number 1", _ArrayMin($avArray, 1))
            MsgBox(64, "Max Number",_ArrayMax($avArray,1))

What do you want this second MsgBox to display?

Ok lets say:

inputbox1 5000

inputbox2 0

inputbox3 9000000

and now i push OK button.

Fisrt msgbox appear and it is show me min value in this case it is 0.

Second msgbox appear after this and it is show me another min value in this case it is 0 too.

And the third msgbox appear it is show me 900000.

But where 5000 which i enter?

The 5000 in general is not present in result:(

But my target is get result like below(from low to hi):

0 on first msgbox.

5000 on second msgbox.

900000 on third msgbox.

What i`m doing somethink wrong in this?

P.S i change

MsgBox(64, "Min Number 1", _ArrayMin($avArray, 1))
but i`m unable get result which i want to do.

Thank you again Melba23 for take your gold time for me.

Edited by Sh3llC043r
[size="5"] [/size]
Link to comment
Share on other sites

  • Moderators

Sh3llC043r,

You need to sort the array itself - _ArrayMin and _ArrayMax will, as their names suggest, only get you the minimum and maximum values.

This should be what you need:

#include <GUIConstantsEx.au3>
#include <Array.au3>

Global $avArray[3], $Input[UBound($avArray)]

$Form1 = GUICreate("", 205, 322, 283, 156)
$Input[0] = GUICtrlCreateInput("", 48, 64, 113, 21)
$Input[1] = GUICtrlCreateInput("", 48, 128, 113, 21)
$Input[2] = GUICtrlCreateInput("", 48, 192, 113, 21)
$Button1 = GUICtrlCreateButton("OK", 64, 256, 81, 25, 0)
$Label1 = GUICtrlCreateLabel("              ENTER DIGITS", 16, 8, 122, 17)
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            For $i = 0 To UBound($avArray) - 1
                $avArray[$i] = Number(GUICtrlRead($Input[$i]))
            Next

            _ArraySort($avArray)

            For $i = 0 To UBound($avArray) - 1
                MsgBox(64, "$i", $avArray[$i])
            Next

    EndSwitch
WEnd

;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...