Jump to content
TheDcoder

Help with defining arrays

Recommended Posts

Hello, I am using this function:

Func ListScripts($sPath)
    Local $aFilesAU3 = _FileListToArray($sPath, "*.au3", 1, True)
    If @error = 4 Then
        Local $aFilesAU3[1]
        $aFilesAU3[0] = 0
    EndIf
    Local $aFilesA3X = _FileListToArray($sPath, "*.a3x", 1, True)
    If @error = 4 Then
        Local $aFilesA3X[1] = 0
        $aFilesA3X[0] = 0
    EndIf
    If $aFilesAU3[0] = 0 And $aFilesAU3[0] = 0 Then Return
    Local $aReturn[UBound($aFilesAU3) + UBound($aFilesA3X) - 2]
    $aReturn[0] = $aFilesAU3[0] + $aFilesA3X[0]
    $iFileCount = $aFilesAU3[0] + $aFilesA3X[0]
    For $i = 1 To $aFilesAU3[0]
        $aReturn[$i] = $aFilesAU3[$i]
    Next
    _ArrayConcatenate($aReturn, $aFilesA3X, 1)
    Return $aReturn
EndFunc

But It works only when the path contains both au3 & a3x files

I get this error: Missing subscript dimensions in "Dim" statement.

 

Thanks in advance, TD :)


A cross-platform implementation of the AutoIt language

My contributions to the AutoIt Community ##AutoIt at freenode, real-time chat

3fHNZJ.gif

Spoiler

If I have hurt or offended you in anyway, Please accept my apologies, I never (regardless of the situation) intend to do that to anybody.

Share this post


Link to post
Share on other sites

If $aFilesAU3[0] = 0 And $aFilesAU3[0] = 0

going to guess you meant to check the a3x array with one of those


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

Share this post


Link to post
Share on other sites

Instead of using _FileListToArray twice, you could use _FileListToArrayRec in non-recursive mode :

#Include <Array.au3>
#Include <File.au3>

ListScripts(@ScriptDir)

Func ListScripts($sPath)
    Return _FileListToArrayRec($sPath, "*.au3;*.a3x", 1, 0, 0, 1)
EndFunc

Edit : Luigi was faster...

Edited by jguinch

Share this post


Link to post
Share on other sites

TheDcoder,

This works for me:

#include <Array.au3>
#include <File.au3>

$sPath = @ScriptDir



_ArrayDisplay(ListScripts($sPath), "", Default, 8)

Func ListScripts($sPath)
    Local $aFilesAU3 = _FileListToArray($sPath, "*.au3", 1, True)
    If @error = 4 Then
        Local $aFilesAU3[1] = [0]
    EndIf

    Local $aFilesA3X = _FileListToArray($sPath, "*.a3x", 1, True)
    If @error = 4 Then
        Local $aFilesA3X[1] = [0]
    EndIf

    ; Check if any returns
    If $aFilesAU3[0] + $aFilesAU3[0] = 0 Then Return "" ; Best to return something!
    ; Concatenate the arrays
    _ArrayConcatenate($aFilesAU3, $aFilesA3X, 1)
    ; Add the count of the second array
    $aFilesAU3[0] += $aFilesA3X[0]
    ; Return the concatenated array
    Return $aFilesAU3
EndFunc

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

 

Share this post


Link to post
Share on other sites

Thanks @Luigi & @jguinch!

I adopted Melba's version of ListScripts, Thanks a lot @Melba23 for the less resource consumptive function :)


A cross-platform implementation of the AutoIt language

My contributions to the AutoIt Community ##AutoIt at freenode, real-time chat

3fHNZJ.gif

Spoiler

If I have hurt or offended you in anyway, Please accept my apologies, I never (regardless of the situation) intend to do that to anybody.

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 sksbir
      Hi
      Trying this from autoit v3.3.14.5 and SCITE 3.19.102.1901.0 :
      help file , page "Language Reference - Variables" , sample autoit script about maps:

      Maps must be declared before use by defining their scope using the 'Global/Local/Static' keywords. Local $mControls[]
      So is my test script : only with this local declation.
      -check syntax is OK
      - running script : 

      test.au3" (13) : ==> Variable subscript badly formatted.: Local $mControls[] Local $mControls[^ ERROR ->14:51:49 AutoIt3.exe ended.rc:1
      any clue ?
    • By Blitzkid
      Hello, i want to search several directories for files with the largest numbers behind them (Like "video123") . They dont have a datatype. But there are also files with longer names and datatypes in these folders (Like "video778.mp4"). Is it possible to filter the _FileListToArray Syntax from
      to smth. like
       
      Here is my Code
      #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <array.au3> #include <File.au3> $filedir = @ScriptDir & "\" _checkfile() Func _checkfile() ConsoleWrite("______________________" & @CRLF) Local $arr[3] = ["music", "picture", "video"] For $i = 0 To UBound($arr) - 1 Local $arrayfiles = _FileListToArray($filedir & $arr[$i], $arr[$i] & "*", 1) If @error = 1 Then ConsoleWrite($arr[$i] & "Error 1") EndIf If @error = 4 Then ConsoleWrite($arr[$i] & "Error 2") ;Exit EndIf $arrayfilter = _ArrayMax($arrayfiles, 0, 1) Global $stringfiles = StringReplace($arrayfilter, $arr[$i], "") ConsoleWrite($arrayfilter & @CRLF) Next EndFunc ;==>_checkfile  
    • By jmp
      Script running good but error in line 7.
      When i run this script :
      #include <IE.au3> #include <Array.au3> $oIE = _IEAttach ("Shop") $oTable = _IETableGetCollection ($oIE, 1) $aTableData = _IETableWriteToArray ($oTable) For $inumber = 1 To UBound($aTableData) -1 $table = $aTableData[4][$inumber] MsgBox(0, "", $table) Next I got Error: array variable has incorrect number of subscripts or subscript dimension range exceeded
    • By nacerbaaziz
      Good morning guys, i hope that you're all well.
      guys, i have a problem and i hope that you can help me
      i've created an 3d array
      the array Contain a Categories info
      as folow
      $array[n][0][0] = Categorie name
      $array[n][0][1] = Categorie file path
      $array[n][0][2] = Categorie contents number
      $array[n][m][0] = link name
      $array[n][m][1] = link url
      $array[n][m][2] = link section name
      in my tool i want to add an option to delete a Category
      as you know the Categorie mean that must delete a region from the array
      when i tried to use _arrayDelete
      with the 2d array it work well
      but here i couldn't find any way to do that, can any one help me please?
      thanks in advance.
    • By nacerbaaziz
      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
×
×
  • Create New...