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

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 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 on other sites

You can try:

`Local \$aFilesAU3 = _FileListToArrayRec(\$sPath, "*.au3;a3x", 1, True)`

Visit my repository

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

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 on other sites

Thanks @Luigi & @jguinch!

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

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.

## Create an account

Register a new account

• ### Similar Content

• Hi dear friends!, i'm sorry for creating a new thread (a new problem), i have over than 9 lists that i want to combine them to be this (in this example, there are 3 test files):

I've written a little code for splitting main information, but i really confused how to make results as "Output.txt", here is that code:

\$sRegex_1 = StringRegExp(FileRead("1.txt"), '(?s:(?<=\=\=\r\n)(.*?)(?=\r\n\=\=))', 3) \$sRegex_2 = StringRegExp(FileRead("2.txt"), '(?s:(?<=\=\=\r\n)(.*?)(?=\r\n\=\=))', 3) \$sRegex_3 = StringRegExp(FileRead("3.txt"), '(?s:(?<=\=\=\r\n)(.*?)(?=\r\n\=\=))', 3) For \$i = 0 To UBound(\$sRegex_1) - 1 ConsoleWrite(\$sRegex_1[\$i] & @CRLF) For \$j = 0 To UBound(\$sRegex_2) - 1 ConsoleWrite(\$sRegex_2[\$j] & @CRLF) For \$k = 0 To UBound(\$sRegex_3) - 1 ConsoleWrite(\$sRegex_3[\$k] & @CRLF) Next Next Next

• hello evrybody
here is an example about how to split your texts using a delimiter with the ability to select how much of delimiters shows in each colum  with \$i_number
e.g
you have a long text and you want to split it in an array
that evry colum have a number (n) of lines
i made a function that do that for you
just call it with a three params
\$s_text
\$i_number
the number that you want to put in each col
\$s_siparator
the siparator
default is "|"
here is the function with example
i hope that it will be useful for you

****

#include <Array.au3> \$s_txt = "some text1some text2|some text3|some text4|some text5|some text6" \$array = splitText(\$s_txt, 2) _ArrayDisplay(\$array) Func splitText(\$s_text, \$i_number, \$s_siparator = "|") Local \$a_TXT = StringSplit(\$s_text, \$s_siparator) Local \$a_Return[\$a_TXT[0] + 1] If (\$a_TXT[0] <= \$i_number) Or (\$i_number <= 0) Then ReDim \$a_Return[2] \$a_Return[0] = 1 \$a_Return[1] = \$s_text Return \$a_Return EndIf Local \$i_Processed = 1, \$i_arrayProcessed = 1 Do For \$i = \$i_Processed To (\$i_Processed + \$i_number) - 1 If (\$a_TXT[0] < \$i) Then ExitLoop If Not (\$a_Return[\$i_arrayProcessed]) Then \$a_Return[\$i_arrayProcessed] = \$a_TXT[\$i] Else \$a_Return[\$i_arrayProcessed] &= \$s_siparator & \$a_TXT[\$i] EndIf \$i_Processed += 1 Next \$i_arrayProcessed += 1 Until (\$a_TXT[0] < \$i_Processed) ReDim \$a_Return[\$i_arrayProcessed] \$a_Return[0] = \$i_arrayProcessed - 1 Return \$a_Return EndFunc ;==>splitText
accept my greetings
thanks to
@Dan_555
for his notes

• good morning
this is the first post here in the autoit forums
i hope that you can help me in my problem
i have a JSON encoded
it a map of my forums
where i want to make a treeview that have the same type of map
e.g
a system (as category)
windows (as sub category)
software (as an child item in the windows category)
.....
i don't know how to do that
so, i know that i can do that using the json functions
but i need your help about how we can do it as the type that i told you
by the way i need to put the sub info for each item in an array that give me the ability to manage my items
e.g
message cound ...
you just give me a small example and i can continue.
am sorry if this against the rules of the forum.
but i realy searched a lot but i couldn't
i hope some one give me the way.
thank you very much in advance

here is the link of json forum
https://www.autoitscript.com/forum/topic/148114-a-non-strict-json-udf-jsmn/
and here is my encoded json file

• I need to dynamically resize my 2d array while looping.
I know this code:
ReDim \$rArray[UBound(\$rArray) + 1] works for the rows, however, I also need to increase the columns. How would i go about increasing both rows and columns while looping?
• By Zaoka
Hi guys
Need little help with filtering.
I'm trying to filter specific weeks from power pivot table using this code recorded with Excel VBA :

#include <Excel.au3> Global \$oExcel = _Excel_Open() Global \$oWorkbook = _Excel_BookOpen(\$oExcel, "C:\Users\....\Orders.xlsb") \$oWorkbook.PivotTables("PivotTable1").PivotFields( _ "[Report 2].[Week].[Week]").VisibleItemsList = Array( _ "[Report 2].[Week].&[10]", "[Report 2].[Week].&[11]", _ "[Report 2].[Week].&[12]", "[Report 2].[Week].&[13]", _ "[Report 2].[Week].&[14]", "[Report 2].[Week].&[15]") But get error
error: Array(): undefined function. Not sure how to resolve this.
×

• Wiki

• Back

• #### Beta

• Git
• FAQ
• Our Picks
×
• Create New...