Jump to content

Array2D


Recommended Posts

Hello, one question.

how can i sort a 2D Array??

can i sort by one or more fields??

Thanks!!!!!

You can use _ArraySort(). Just be sure to add #include <Array.au3> to your code as well.

- MoChr(77)& Chr(97)& Chr(100)& Chr(101)& Chr(32)& Chr(121)& Chr(97)& Chr(32)& Chr(108)& Chr(111)& Chr(111)& Chr(107)-------I've told you 100,000 times not to exaggerate!-------Don't make me hit you with my cigarette hand...-------My scripts:Random Episode Selector, Keyboard MouseMover, CopyPath v2.1, SmartRename for XP,Window Tracer[sup]New![/sup]

Link to comment
Share on other sites

You can use _ArraySort(). Just be sure to add #include <Array.au3> to your code as well.

thanksss

i tried this

#include <Array.au3>
#include <SQLite.au3>
Local $aResult, $iRows, $iColumns, $iRval

_SQLite_Startup ()
If @error > 0 Then
    MsgBox(16, "SQLite Error", "SQLite.dll Can't be Loaded!")
    Exit - 1
EndIf
_SQLite_Open (); Open a :memory: database
If @error > 0 Then
    MsgBox(16, "SQLite Error", "Can't Load Database!")
    Exit - 1
EndIf

;Example Table
;   Name        | Age
;   -----------------------
;   Alice      | 43
;   Bob      | 28
;   Cindy      | 21

If Not _SQLite_Exec (-1, "CREATE TEMP TABLE persons (Name, Age);") = $SQLITE_OK Then _
        MsgBox(16, "SQLite Error", _SQLite_ErrMsg ())
If Not _SQLite_Exec (-1, "INSERT INTO persons VALUES ('Alice','43');") = $SQLITE_OK Then _
        MsgBox(16, "SQLite Error", _SQLite_ErrMsg ())
If Not _SQLite_Exec (-1, "INSERT INTO persons VALUES ('Cindy','21');") = $SQLITE_OK Then _
        MsgBox(16, "SQLite Error", _SQLite_ErrMsg ())
If Not _SQLite_Exec (-1, "INSERT INTO persons VALUES ('Bob','28');") = $SQLITE_OK Then _
        MsgBox(16, "SQLite Error", _SQLite_ErrMsg ())


; Query
$iRval = _SQLite_GetTable2d (-1, "SELECT * FROM persons;", $aResult, $iRows, $iColumns)
If $iRval = $SQLITE_OK Then
    _SQLite_Display2DResult($aResult)

Else
    MsgBox(16, "SQLite Error: " & $iRval, _SQLite_ErrMsg ())
EndIf
;~ MsgBox(0,"","")
_SQLite_Close ()
_SQLite_Shutdown ()



_ArrayDisplay($aResult)


$a_Array = $aResult
$i_Descending = 1
$i_Base = 1
$i_Ubound = -1
$i_Dim = UBound($aResult,2)
$i_SortIndex = 0

_ArraySort ( $aResult , $i_Descending , $i_Base , $i_Ubound , $i_Dim , $i_SortIndex )

_ArrayDisplay($aResult)

but i dont sort

please heeelpp

thank for your reply!!!

Edited by soyfelix
Link to comment
Share on other sites

Hi,

You displayed the unsorted array again at the end;

try

_ArrayDisplay($a_Array)oÝ÷ ÚÚºÚ"µÍÌÍÚT[HÔÔS]WÑÙ]XL
LK  ][ÝÔÑSPÕ
ÓHÛÛÈÔTH[YNÉ][ÝË    ÌÍØTÝ[  ÌÍÚTÝÜË   ÌÍÚPÛÛ[[Ê

Randall

Edited by randallc
Link to comment
Share on other sites

Hi,

You displayed the unsorted array again at the end;

try

CODE: AutoIt

_ArrayDisplay($a_Array)

or;

CODE: AutoIt

$iRval = _SQLite_GetTable2d (-1, "SELECT * FROM persons ORDER BY Name;", $aResult, $iRows, $iColumns)

Thank, i made a mistake....jejejeje.

with parameters i can sort by one col

#include <Array.au3>
#include <SQLite.au3>
Local $aResult, $iRows, $iColumns, $iRval

_SQLite_Startup ()
If @error > 0 Then
    MsgBox(16, "SQLite Error", "SQLite.dll Can't be Loaded!")
    Exit - 1
EndIf
_SQLite_Open (); Open a :memory: database
If @error > 0 Then
    MsgBox(16, "SQLite Error", "Can't Load Database!")
    Exit - 1
EndIf
If Not _SQLite_Exec (-1, "CREATE TEMP TABLE persons (Year, Count_Failed);") = $SQLITE_OK Then _
        MsgBox(16, "SQLite Error", _SQLite_ErrMsg ())
If Not _SQLite_Exec (-1, "INSERT INTO persons VALUES ('2008','43');") = $SQLITE_OK Then _
        MsgBox(16, "SQLite Error", _SQLite_ErrMsg ())
If Not _SQLite_Exec (-1, "INSERT INTO persons VALUES ('2008','21');") = $SQLITE_OK Then _
        MsgBox(16, "SQLite Error", _SQLite_ErrMsg ())
If Not _SQLite_Exec (-1, "INSERT INTO persons VALUES ('2008','28');") = $SQLITE_OK Then _
        MsgBox(16, "SQLite Error", _SQLite_ErrMsg ())
If Not _SQLite_Exec (-1, "INSERT INTO persons VALUES ('2007','43');") = $SQLITE_OK Then _
        MsgBox(16, "SQLite Error", _SQLite_ErrMsg ())
If Not _SQLite_Exec (-1, "INSERT INTO persons VALUES ('2008','24');") = $SQLITE_OK Then _
        MsgBox(16, "SQLite Error", _SQLite_ErrMsg ())
If Not _SQLite_Exec (-1, "INSERT INTO persons VALUES ('2007','1');") = $SQLITE_OK Then _
        MsgBox(16, "SQLite Error", _SQLite_ErrMsg ())
; Query
$iRval = _SQLite_GetTable2d (-1, "SELECT * FROM persons;", $aResult, $iRows, $iColumns)
If $iRval = $SQLITE_OK Then

Else
    MsgBox(16, "SQLite Error: " & $iRval, _SQLite_ErrMsg ())
EndIf
_SQLite_Close ()
_SQLite_Shutdown ()


_ArrayDisplay($aResult)

$rows = UBound($aResult)
$cols = UBound($aResult, 2)
$dims = UBound($aResult, 0)


$a_Array = $aResult
$i_Descending = 0; 1 = descending 0 Ascending
$i_Base = 1; Fila por la que comienza, si pongo cero incluye la cabecera
$i_Ubound = UBound($aResult); El número de filas a ordenar 
$i_Dim = UBound($aResult,2); Número de columnas de la 2 dimension
$i_SortIndex = 1; Columna por la que ordeno

_ArraySort ( $aResult , $i_Descending , $i_Base , $i_Ubound , $i_Dim , $i_SortIndex )

_ArrayDisplay($aResult)

if i change $i_SortIndex i can sort by different column, but my answer is: Can I sort by two col??

For example, i would like sort by year and count_failed.

Thankssssssssssssssssssssssssssssssss

Link to comment
Share on other sites

or;

; sqlitesort3.au3
#include <Array2D.au3>
#include <SQLite.au3>
Local $aResult, $iRows, $iColumns, $iRval

_SQLite_Startup ()
If @error > 0 Then
    MsgBox(16, "SQLite Error", "SQLite.dll Can't be Loaded!")
    Exit - 1
EndIf
_SQLite_Open (); Open a :memory: database
If @error > 0 Then
    MsgBox(16, "SQLite Error", "Can't Load Database!")
    Exit - 1
EndIf
If Not _SQLite_Exec (-1, "CREATE TEMP TABLE persons (Year, Count_Failed);") = $SQLITE_OK Then _
        MsgBox(16, "SQLite Error", _SQLite_ErrMsg ())
If Not _SQLite_Exec (-1, "INSERT INTO persons VALUES ('2008','43');") = $SQLITE_OK Then _
        MsgBox(16, "SQLite Error", _SQLite_ErrMsg ())
If Not _SQLite_Exec (-1, "INSERT INTO persons VALUES ('2008','21');") = $SQLITE_OK Then _
        MsgBox(16, "SQLite Error", _SQLite_ErrMsg ())
If Not _SQLite_Exec (-1, "INSERT INTO persons VALUES ('2008','28');") = $SQLITE_OK Then _
        MsgBox(16, "SQLite Error", _SQLite_ErrMsg ())
If Not _SQLite_Exec (-1, "INSERT INTO persons VALUES ('2007','43');") = $SQLITE_OK Then _
        MsgBox(16, "SQLite Error", _SQLite_ErrMsg ())
If Not _SQLite_Exec (-1, "INSERT INTO persons VALUES ('2008','24');") = $SQLITE_OK Then _
        MsgBox(16, "SQLite Error", _SQLite_ErrMsg ())
If Not _SQLite_Exec (-1, "INSERT INTO persons VALUES ('2007','1');") = $SQLITE_OK Then _
        MsgBox(16, "SQLite Error", _SQLite_ErrMsg ())
; Query
$iRval = _SQLite_GetTable2d (-1, "SELECT * FROM persons;", $aResult, $iRows, $iColumns)
;~ $iRval = _SQLite_GetTable2d (-1, "SELECT * FROM persons ORDER BY Year,Count_Failed;", $aResult, $iRows, $iColumns)
If $iRval = $SQLITE_OK Then

Else
    MsgBox(16, "SQLite Error: " & $iRval, _SQLite_ErrMsg ())
EndIf
_SQLite_Close ()
_SQLite_Shutdown ()


_ArrayDisplay($aResult)

_ArrayDelete2D( $aResult, 0)
_ArrayDisplay($aResult)
_Array2D1DFieldSortSt( $aResult,"1|2")
$aResult=_Array2DCreateFromArraySt($aResult)
_ArrayDisplay($aResult)
Randall
Link to comment
Share on other sites

Exactly!!!! your last post is that i want!!!

im looking for this in the forum, but i only found sort by one col. I was reading your post about your function "Array2D1DFieldSortSt" and im testing it.

i want use sort and subsort because i have a lot "select" in my code and i want optimice it for easy read.

Thanks very much. Im going to test your includes.!!!!!!!!!!!!!!!!!!!!!!! :)

Link to comment
Share on other sites

Hi,

Glad to help. though I would have thought doing it SQL woyld be more reliable? [ie post before];

$iRval = _SQLite_GetTable2d (-1, "SELECT * FROM persons ORDER BY Year,Count_Failed;", $aResult, $iRows, $iColumns)
Or would it slow things down if you had to select repeatedly?

Best, randall

Link to comment
Share on other sites

Hi,

Glad to help. though I would have thought doing it SQL woyld be more reliable? [ie post before];

$iRval = _SQLite_GetTable2d (-1, "SELECT * FROM persons ORDER BY Year,Count_Failed;", $aResult, $iRows, $iColumns)
Or would it slow things down if you had to select repeatedly?

Best, randall

I made a Gui with a lot of control, its a "poyects date control", and the records are showed in a list view, the lines of the LV have subimages (icons and text) and the UDF to sort LV (_GUICtrlListViewSort ( $h_listview, ByRef $v_descending, $i_sortcol )) does not sort good(or i dont know to work it) because it sort the text but does not sort the subimages. Now i sort with SQLite, but i have a loooottttt offff line of this and like learn with the internal tables and compare with my actual code, anything else!!!

thanks very much for your help, and excuse me for my english, its very basic...jejejeje

byeeeeeeeeeeeeeeeee!!!!!!

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...