Jump to content

Array in Array


Recommended Posts

Hi all,

I think i have a silly question, but iam stuck and i need some help :)

I have the following code;

; Article
Global $configfile_artikel[25]
local $cx = 0

Do

Local $configfile_artikel[$cx] = StringSplit($configfile_contents[$cx+2], "=", 0)

$cx = $cx + 1

Until $cx = 23

EndIf

But if i execute this code, i will get an error; Missing subscript dimensions in "Dim" statement.

 

I have tried several codes, but i need to create an array in an array and it is failing,.

 

Can you guys help me with this?

 

Thanks!

Link to comment
Share on other sites

Could you post a working reproducer? That one is broken on many points...

Here is a working example of arrays in arrays:

#include <Array.au3>

Global $firstInner[2] = ["hi", "bye"]
Global $secondInner[2] = ["one", "two"]
Global $outer[2] = [$firstInner, $secondInner]

For $ar In $outer
    _ArrayDisplay($ar)
Next

/edit: exit beat me :)

Edited by SadBunny

Roses are FF0000, violets are 0000FF... All my base are belong to you.

Link to comment
Share on other sites

Hi all,

Thanks for the examples, here is a complete script!

#include <FileConstants.au3>
#include <MsgBoxConstants.au3>
#include <GUIConstants.au3>
#include <Crypt.au3>
#include <ColorConstants.au3>
#include <GUIConstantsEx.au3>
#include <ComboConstants.au3>
#include <Array.au3>
#include <String.au3>
#include <ProgressConstants.au3>
#include <IE.au3>
#include <WindowsConstants.au3>
#include <BlockInputEx.au3>
#include <File.au3>
#include <APIConstants.au3>
#include <WinAPIEx.au3>
#include <GuiButton.au3>

; Bestaat config file?
Local $iFileExists = FileExists("favotool.conf")

If $iFileExists = 1 Then

; Kijk of configfile bestaat, zoja roep gegevens op
Local $configfile = FileRead("favotool.conf")
Local $configfile_contents = StringSplit($configfile, @CRLF, 0)

; Artikelen
Global $configfile_artikel[25]
local $cx = 0

Do

Local $configfile_artikel[$cx] = StringSplit($configfile_contents[$cx+2], "=", 0)

$cx = $cx + 1

Until $cx = 23

EndIf

 

:favotool.conf

Magazijnnummer=435
0=~~~~4
1=~~~~4
2=~~~~4
3=~~~~4
4=~~~~4
5=~~~~4
6=~~~~4
7=~~~~4
8=~~~~4
9=234243~11111~TESTING1~3~1
10=~~~~4
11=~~~~4
12=~~~~4
13=~~~~4
14=435435~444~TESTING2~2~4
15=~~~~4
16=~~~~4
17=~~~~4
18=~~~~4
19=~~~~4
20=~~~~4
21=~~~~4
22=~~~~4

 

I am trying to call a variable with;

$xc = 0

Do

GUICtrlCreateInput($configfile_artikel_output[$xc][2],30,$height,90,20,0x0001)

$xc = $xc + 1

Until $xc = 23

 

Edited by Blueman
Link to comment
Share on other sites

  • Moderators

Blueman,

I have no idea why you are using all those includes - here is a version which seems to work:

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

; Bestaat config file?
Local $iFileExists = FileExists("favotool.conf")

If $iFileExists = 1 Then

    ; Kijk of configfile bestaat, zoja roep gegevens op
    Local $configfile = FileRead("favotool.conf")
    Local $configfile_contents = StringSplit($configfile, @CRLF, $STR_ENTIRESPLIT) ; If you want each line in an element you need the $STR_ENTIRESPLIT flag
    _ArrayDisplay($configfile_contents, "Your way", Default, 8)

    ; But it is much easier to do this
    Local $configfile_contents
    _FileReadToArray("favotool.conf", $configfile_contents)
    _ArrayDisplay($configfile_contents, "Easy way", Default, 8)

    ; Artikelen

    Global $configfile_artikel[25]
    Local $cx = 0

    Do

        $configfile_artikel[$cx] = StringSplit($configfile_contents[$cx + 2], "=")

        $cx = $cx + 1

    Until $cx = 23

    ; The array holding the arrays
    _ArrayDisplay($configfile_artikel, "", Default, 8)
    ; An internal array
    _ArrayDisplay($configfile_artikel[9], "", Default, 8)

EndIf

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

Blueman,

2 errors made your code wrong :

- as Melba said,  StringSplit(..., @CRLF, 1) it needs the flag 1 ( = $STR_ENTIRESPLIT) because CRLF contains 2 chars (CR+LF)
- Local $configfile_artikel[$cx]  (in the Do  loop) means a declaration so you get the "Missing subscript dimensions" error

Use flag 1 in the StringSplit, remove the "Local" and the code works  :)

Link to comment
Share on other sites

Thanks guys, works like a charm!

Now i have to figure out how to get the value from eg; $configfile_artikel[$cx][2]

But i think thats simple :)

Thanks again!

EDIT: I used _ArrayToString($configfile_artikel[$cx], "", 2, 2) For that :)

Edited by Blueman
Link to comment
Share on other sites

  • Moderators

Blueman,

how to get the value from eg; $configfile_artikel[$cx][2]

($configfile_artikel[$cx])[2]

Note the ( ) around the first section.

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

Here another example:

#AutoIt3Wrapper_Version=b

#include <Array.au3>

Global $sText = "This is an example for array in an array :-)"
Global $aArray_Main[2] = ["Index = 0", StringSplit($sText, " ", 2)]

ConsoleWrite("Modifying value " & ($aArray_Main[1])[9] & @CRLF)
_ArrayMod($aArray_Main[1], ";-)", 9) ;modify 9th entry in nested array :-) -> ;-)

_ArrayDisplay($aArray_Main[1], "Sub Array")

Func _ArrayMod(ByRef $aArray, $vValue, $iIndex) ;no error checks!
    $aArray[$iIndex] = $vValue
EndFunc

 

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

Are there any benefits using this method instead of 2D-Arrays?

​You generally don't want to do this, as it makes things harder because accessing elements in the internal array isn't as easy to code as accessing 2D array elements.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

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