Jump to content

Recommended Posts

Posted (edited)

hello sirs, please help me

i tried to create a function that read a folder files to 3d array

e.g

$array[n][0][0] = ctName

$array[n][0][1] = ctFilePath

$array[n][0][2] = crtsections number

$array[n][m][0] = KeyName

$array[n][m][1] = KeyVal

$array[n][m][2] = keySectionName

 

that the array

when i put one file into the folder all things work fine

but when i put more than one file

the last file worked fine but the others only the first key is showing

please can you help me to correct this problem

here is the example with the folder

please accept my greetings

and thanks in advance

 

array3d.zip

Edited by nacerbaaziz
added the tags
Posted

@czardas arrayworkshop is a great thread for learning more than you want,  the fruit cube is how i got comfortable manipulating stuff

 

 

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

Posted

my problem isn't in the array creation

 until now i can't know where is the problem exact

please if any one of you can download and try to tell me where is the problem

thx in advance 

Posted

I've got the files but what I don't understand is what attributes or data you want to assign to each array dimension and what you want to store in each array cell.

AFAICT you only need a 2D array, so I must be overlooking something important to you.

A 3D array is perfect to represent, for instance, one attribute of points in cartesian coordinates: if (X, Y, Z) are point coordinates in air, the array may store, for instance, the température of air at that point.  Then the array once filled gives you T° = f(X, Y, Z).

How does this simple example apply to your data?

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Posted
8 minutes ago, jchd said:

I've got the files but what I don't understand is what attributes or data you want to assign to each array dimension and what you want to store in each array cell.

AFAICT you only need a 2D array, so I must be overlooking something important to you.

A 3D array is perfect to represent, for instance, one attribute of points in cartesian coordinates: if (X, Y, Z) are point coordinates in air, the array may store, for instance, the température of air at that point.  Then the array once filled gives you T° = f(X, Y, Z).

How does this simple example apply to your data?

am making an links store

and that tool has a categorys

and evry category is in a file

that file as a ini file

and what i want is to store the data in a 3d array

that the 1d to change the categorys and the 2d is to change the ini sections, and the last is to store the links information as the name of link and the url

i hope that you understand what i want

Posted

You only need a 2D array:

Category    LinkName    URL
test    faceBook    https://facebook.com/
test    twitter https://twitter.com/
test    honeygain   https://honeygain.com/
test2   google  https://google.com/
test2   gmail   https://gmail.com/
test2   youtube https://youtube.com/
test3   mx-blind    https://mx-blind.com/
test3   wordpress   https://wordpress.com/
test3   blind help  https://blindhelp.net/

This is TSV format so you can copy-paste and directly load into a 2D array. Leave the headers alone as it will simplify access.

BTW if you intent to have a large number of links, you might turn to SQLite.

Here's a SQL source file (containing SQLite-compatible statements) you can use to create the database corresponding to the table shown above:

Links.sql

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Posted

i liked to use the 3d because i have a treeview and list box

for that to get the info from one to one i must use a array

but if you mean that no whey to do that, then i have to change all my function .

i hope any one can help me to correct that 

Posted
4 minutes ago, nacerbaaziz said:

i liked to use the 3d because i have a treeview and list box

for that to get the info from one to one i must use a array

I provided an example of use of an array, didn't I?

I still fail to see how you would cram your data in 3 dimensions, still keeping ease of use, access, search and coding.  I'm not saying this is impossible, just that it's neither useful nor practical.

To make a parallel, think about a personal address book. A (very simple) address consists of: country, state, zipcode, city, street, number, floor, appartment number.  That's 8 entities for that simple case, many real-world addresses are much more complex.

There are two diametrally extreme ways to organize storage for addresses like that: a 2D-array where each entry (row) contains 8 columns to store the 8 components, or a 8D-array where each component represents a dimension.

A 2D-array fits well the personal use, but a 8D array is most suitable for administrative registers that lists all habitations/appartments in a large area.  Searching in a 2D array is much easier than selecting address components in a 8D-array.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Posted

Does this function contain any errors, please?

#include <iniex.au3>
#include <Array.au3>
#include <File.au3>
#include <fileOptions.au3>
Global $A_StoreDataRead[1][1][3]
Global $StoreDataDir = @ScriptDir & "\store_data"
Store_GetData()
Func Store_GetData($DataDir = $StoreDataDir)

    ReDim $A_StoreDataRead[1][1][3]

    Local $find = _FileListToArrayRec($DataDir, "*.CTG", $FLTAR_FILES, $FLTAR_NORECUR, $FLTAR_SORT, $FLTAR_FULLPATH)
    If $find[0] <= 0 Then Return SetError(1, 0, 1)


    Local $iAll = 0, $i = 1, $CrntPath = "", $sectionsRead, $SectionRead, $crntPathOpen, $CrntPathRead, $crntFileName
    For $iFiles = 1 To $find[0]

        $CrntPath = $find[$iFiles]
        $crntFileName = _GetFileName($CrntPath)
        $crntPathOpen = FileOpen($CrntPath)
        $CrntPathRead = FileRead($crntPathOpen)
        If @error Then
            FileClose($crntPathOpen)
            ContinueLoop
        EndIf
        FileClose($crntPathOpen)

        $sectionsRead = _IniReadSectionNamesFromString($CrntPathRead)
        If @error Then ContinueLoop
        $iAll += 1
        $i = 1
        For $scs = 1 To $sectionsRead[0]
            $i += 1
            ReDim $A_StoreDataRead[$iAll + 1][$i][3]
            If $sectionsRead[$scs] = "categoryInfo" Then
                $A_StoreDataRead[$iAll][0][0] = _IniReadFromString($CrntPathRead, "categoryInfo", "categoryName", "")
                $A_StoreDataRead[$iAll][0][1] = $crntFileName
                $i -= 1
            Else
                $A_StoreDataRead[$iAll][$i - 1][0] = _IniReadFromString($CrntPathRead, $sectionsRead[$scs], "linkName", "")
                $A_StoreDataRead[$iAll][$i - 1][1] = _IniReadFromString($CrntPathRead, $sectionsRead[$scs], "LinkValue", "")
                $A_StoreDataRead[$iAll][$i - 1][2] = $sectionsRead[$scs]
                $A_StoreDataRead[$iAll][0][2] = $i - 1
            EndIf
            MsgBox(64, "result", $A_StoreDataRead[$iAll][0][0] & @CRLF & $A_StoreDataRead[$iAll][0][1] & @CRLF & $A_StoreDataRead[$iAll][0][2] & @CRLF & $A_StoreDataRead[$iAll][$i - 1][0] & @CRLF & $A_StoreDataRead[$iAll][$i - 1][1] & @CRLF & $A_StoreDataRead[$iAll][$i - 1][2])
        Next
    Next
    $A_StoreDataRead[0][0][0] = $iAll

    MsgBox(64, "", $A_StoreDataRead[1][0][0] & @CRLF & $A_StoreDataRead[1][0][1] & @CRLF & $A_StoreDataRead[1][0][2])
    MsgBox(64, "", $A_StoreDataRead[1][1][0] & @CRLF & $A_StoreDataRead[1][1][1] & @CRLF & $A_StoreDataRead[1][1][2])
    MsgBox(64, "", $A_StoreDataRead[1][2][0] & @CRLF & $A_StoreDataRead[1][2][1] & @CRLF & $A_StoreDataRead[1][2][2])
    MsgBox(64, "", $A_StoreDataRead[1][3][0] & @CRLF & $A_StoreDataRead[1][3][1] & @CRLF & $A_StoreDataRead[1][3][2])

    MsgBox(64, "", $A_StoreDataRead[2][0][0] & @CRLF & $A_StoreDataRead[2][0][1] & @CRLF & $A_StoreDataRead[2][0][2])
    MsgBox(64, "", $A_StoreDataRead[2][1][0] & @CRLF & $A_StoreDataRead[2][1][1] & @CRLF & $A_StoreDataRead[2][1][2])
    MsgBox(64, "", $A_StoreDataRead[2][2][0] & @CRLF & $A_StoreDataRead[2][2][1] & @CRLF & $A_StoreDataRead[2][2][2])
    MsgBox(64, "", $A_StoreDataRead[2][3][0] & @CRLF & $A_StoreDataRead[2][3][1] & @CRLF & $A_StoreDataRead[2][3][2])

    MsgBox(64, "", $A_StoreDataRead[3][0][0] & @CRLF & $A_StoreDataRead[3][0][1] & @CRLF & $A_StoreDataRead[3][0][2])
    MsgBox(64, "", $A_StoreDataRead[3][1][0] & @CRLF & $A_StoreDataRead[3][1][1] & @CRLF & $A_StoreDataRead[3][1][2])
    MsgBox(64, "", $A_StoreDataRead[3][2][0] & @CRLF & $A_StoreDataRead[3][2][1] & @CRLF & $A_StoreDataRead[3][2][2])
    MsgBox(64, "", $A_StoreDataRead[3][3][0] & @CRLF & $A_StoreDataRead[3][3][1] & @CRLF & $A_StoreDataRead[3][3][2])


    Return 1
EndFunc   ;==>Store_GetData

 

Posted

hello again

i found the problem, and i wanted to share it with you

here is the corrected function

thank you all to your help

with my greetings

func Store_GetData($DataDir = $StoreDataDir)

ReDim $A_StoreDataRead[1][1][3]

local $find = _FileListToArrayRec($DataDir, "*.CTG", $FLTAR_FILES, $FLTAR_NORECUR, $FLTAR_SORT, $FLTAR_FULLPATH)
    If not (isArray($find)) Then return SetError(1, 0, 1)
local $iAll = 0, $i = 1, $IcrntSec = 1, $CrntPath = "", $sectionsRead, $SectionRead, $crntPathOpen, $CrntPathRead, $crntFileName
for $iFiles = 1 to $find[0]

$crntPath = $find[$iFiles]
$crntFileName = _GetFileName($crntPath)
$crntPathOpen = FileOpen($crntPath)
$CrntPathRead = FileRead($crntPathOpen)
if @Error then
fileClose($crntPathOpen)
ContinueLoop
endIf
fileClose($crntPathOpen)

$SectionsRead = _IniReadSectionNamesFromString($CrntPathRead)
if @Error then ContinueLoop
$iAll += 1
$i = 1
for $scs = 1 to $SectionsRead[0]
$i += 1
if $IcrntSec < $i then
ReDim $A_StoreDataRead[$iAll+1][$i][3]
$IcrntSec = $i
else
ReDim $A_StoreDataRead[$iAll+1][$IcrntSec][3]


endIf
if $SectionsRead[$scs] = "categoryInfo" then
$A_StoreDataRead[$iAll][0][0] = _IniReadFromString($CrntPathRead, "categoryInfo", "categoryName", "")
$A_StoreDataRead[$iAll][0][1] = $crntFileName
$i -= 1
else
$A_StoreDataRead[$iAll][$i-1][0] = _IniReadFromString($CrntPathRead, $SectionsRead[$scs], "linkName", "")
$A_StoreDataRead[$iAll][$i-1][1] = _IniReadFromString($CrntPathRead, $SectionsRead[$scs], "LinkValue", "")
$A_StoreDataRead[$iAll][$i-1][2] = $SectionsRead[$scs]
$A_StoreDataRead[$iAll][0][2] = $i-1
endIf

next
next
$A_StoreDataRead[0][0][0] = $iAll

return 1
endFunc

 

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
×
×
  • Create New...