Jump to content

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 :)

EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time)

DcodingTheWeb Forum - Follow for updates and Join for discussion

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

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

Link to comment
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
Link to comment
Share on other sites

  • Moderators

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

 

Link to comment
Share on other sites

Thanks @Luigi & @jguinch!

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

EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time)

DcodingTheWeb Forum - Follow for updates and Join for discussion

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

×
×
  • Create New...