Jump to content

Merging arrays


Recommended Posts

Hello guys !

I've tried to merge 2 arrays together but I am stuck right now. As for merging them i have no problem but theres a blank line added in the middle of it and i can't get it out.

I've tried to delete it but he's not always at the same place.

Also, i can't delete items in the lisview to add them back with the new array merged. Maybe the blank line causing problem ?

Here's the code

Global $Data = "Data.ini", $DataS = IniReadSection($Data, "Data")

$GUI = GUICreate("Data center", 322, 482, 192, 124)
$LV = _GUICtrlListView_Create($GUI, "Data name", 8, 168, 306, 302, BitOr($LVS_REPORT, $LVS_NOSORTHEADER))
_GUICtrlListView_SetExtendedListViewStyle($LV, $LVS_EX_FULLROWSELECT)
_GUICtrlListView_SetColumnWidth($LV, 0, 289)

If $DataS <> 1 Then
    For $i = 1 To $DataS[0][0]
        _GUICtrlListView_AddItem($LV, $DataS[$i][1])
    Next
EndIf

GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Load
            $folder = FileSelectFolder("Select the folder containing your data.", "")
            $DataF = _FileListToArray($folder, "*.dat")
            $Length_A = Ubound($DataS)
            $Length_B = Ubound($DataF)
            ReDim $DataS[$Length_A+$Length_B][2]
            For $i = 1 to $Length_B-1
                $DataS[$Length_A+$i][0]=$folder
                $DataS[$Length_A+$i][1]=$DataF[$i]
            Next

            ;_ArrayDisplay($datas)
            _GUICtrlListView_DeleteAllItems($LV)
            For $i = 1 to $DataS[0][0]
                _GUICtrlListView_AddItem($LV, $DataS[$i][1])
            Next
    EndSwitch
WEnd

As for Data.ini :

[Data]
D:\dat\=testtt.dat
D:\dat\=test111.dat
Edited by Jayson
Link to comment
Share on other sites

A quick attempt to explain the "blank in the middle" would be:

- that "blank" is the element [0] of your second array which you are not using (value = "")

- that blank might be also, an extra (empty) element at the end of your first array

Use a couple msgboxes to show you the UBound for each array before merging them. You will see where the problem is and you could simply delete the culprit before merging.

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Link to comment
Share on other sites

Ty for the tip Posted Image

Ubound show correct size and I saw no empty array with both of them but after the merge the second array ($DataF) lose his element at [0] and make it empty Posted ImagePosted Image

I've deleted it by using _ArraySort then used _ArrayDelete to delete it at the top.

On problem remains : I still can't get the array to load the Listview. Maybe it's because I used this array to load when I launch the program ? Posted Image

Edited by Jayson
Link to comment
Share on other sites

Well - please, next time when you ask for help, post a working script. If you don't, I will refuse any help at all.

I had to waste time to get a working example of your script - also, consider for the future to use arrays instead of ini files when asking for help.

This is working - your job to adapt it to your real script. The mistake was in the ReDim statement - ReDim for the Ubound 1 + Ubound 2 -1

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
#Include <GuiListView.au3>
#Include <array.au3>

Dim $Data1[3][2] = [[2,0],["D:\dat\","testtt.dat"], ["D:\dat\","test111.dat"]]
Dim $Data2[2][2] = [[1,0],["D:\dat\","test222.dat"]]

Opt("GUIOnEventMode", 1)
#Region ### START Koda GUI section ### Form=
$GUI = GUICreate("Form1", 387, 289, 192, 124)
GUISetOnEvent($GUI_EVENT_CLOSE, "Form1Close")
$LV = _GUICtrlListView_Create($GUI, "Data name", 8, 8, 370, 238, BitOr($LVS_REPORT, $LVS_NOSORTHEADER))
_GUICtrlListView_SetExtendedListViewStyle($LV, $LVS_EX_FULLROWSELECT)
_GUICtrlListView_SetColumnWidth($LV, 0, 250)
For $i = 1 To $Data1[0][0]
    _GUICtrlListView_AddItem($LV, $Data1[$i][1])
Next

$Button1 = GUICtrlCreateButton("Button1", 152, 256, 75, 25, $WS_GROUP)
GUICtrlSetOnEvent(-1, "Button1Click")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    Sleep(100)
WEnd

Func Button1Click()
    $Length_A = Ubound($Data1)
    $Length_B = Ubound($Data2)
    ReDim $Data1[$Length_A+$Length_B-1][2]      ;HERE was the error
    For $i = 1 to $Length_B-1
        $Data1[$Length_A+$i-1][0]=$Data2[$i][0]
        $Data1[$Length_A+$i-1][1]=$Data2[$i][1]
    Next
    ;_ArrayDisplay($Data1)
    _GUICtrlListView_DeleteAllItems($LV)
    For $i = 1 to UBound($Data1)-1
        _GUICtrlListView_AddItem($LV, $Data1[$i][1])
    Next

EndFunc
Func Form1Close()
    Exit
EndFunc

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Link to comment
Share on other sites

ReDim $DataS[($Length_A+$Length_B)-1][2]

Edited by GEOSoft

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

Thank you for helping me. I've made it working with my script.

I thought .ini files was easier to show my problem that I had. I'll make sure to use arrays next time Posted Image

Edit : Typign!

Edited by Jayson
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...