Sign in to follow this  
Followers 0
Jayson

1D to 2D then filling List

4 posts in this topic

#1 ·  Posted (edited)

Hello guys,

I'm filling an array using _FileReadToArray then using stringplit and put everything into a 2D array.

Everything goes fine I got all my data there but when comes the time to load it into an list it only load 4 lines.

Here's the code

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

Global $songs
_FileReadToArray(@ScriptDir "Playlist - Copie.ini", $songs) ; Lecture du fichier dans le tableau.
;_ArrayDisplay($songs)

Global $r_songs[$songs[0]][2] ; Préparation tableau2
;_ArrayDisplay($r_songs)

$Mp3 = GUICreate("Mp3 List", 300, 225, -1, -1)
$LV = GUICtrlCreateList("", 5, 100, 290, 130)

For $i = 1 To $songs[0] ; Boucle l'array songs
    Local $s_songs = StringSplit($songs[$i], "=") ; Séparation des éléments
    $r_songs[$i - 1][0] = $s_songs[1] ; Mémorisation dans le tableau2 de la valeur 1
    $r_songs[$i - 1][1] = $s_songs[2] ; Mémorisation dans le tableau2 de la valeur 2
Next
_ArrayDisplay($r_songs)

For $i = 0 To $r_songs[0][0]
    ;_ArrayDisplay($r_songs)
    ;ConsoleWrite($i)
    GUICtrlSetData($LV, $r_songs[$i][0])
Next

GUISetState(@SW_SHOW, $Mp3)

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch

WEnd

and the "playlist - copie.ini"

3 Days Grace - Now Or Never=E:Tounes3 Days Grace - Now Or Never.mp3
3 Doors Down - Kryptonite=E:Tounes3 Doors Down - Kryptonite.mp3
30 Seconds To Mars - Battle Of One=E:Tounes30 Seconds To Mars - Battle Of One.mp3
30 Seconds To Mars - Beautiful Lie=E:Tounes30 Seconds To Mars - Beautiful Lie.mp3
30 Seconds To Mars - Edge of the Earth=E:Tounes30 Seconds To Mars - Edge of the Earth.mp3
30 Seconds To Mars - From Yesterday=E:Tounes30 Seconds To Mars - From Yesterday.mp3
30 Seconds To Mars - I'll Attack=E:Tounes30 Seconds To Mars - I'll Attack.mp3
Edited by Jayson

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

you dont have number as $songs[0][0]

so store array row number in it

#include <File.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
#include <GuiListBox.au3>
Global $songs
_FileReadToArray(@ScriptDir &"\Playlist - Copie.ini", $songs) ; Lecture du fichier dans le tableau.
;_ArrayDisplay($songs)
Global $r_songs[$songs[0]+1][2] ; Préparation tableau2
;_ArrayDisplay($r_songs)
$Mp3 = GUICreate("Mp3 List", 300, 225, -1, -1)
$LV = GUICtrlCreateList("", 5, 100, 290, 130)
$r_songs[0][0] = $songs[0]
For $i = 1 To $songs[0] ; Boucle l'array songs
Local $s_songs = StringSplit($songs[$i], "=") ; Séparation des éléments
$r_songs[$i][0] = $s_songs[1] ; Mémorisation dans le tableau2 de la valeur 1
$r_songs[$i][1] = $s_songs[2] ; Mémorisation dans le tableau2 de la valeur 2
Next
_ArrayDisplay($r_songs)
For $i = 1 To $r_songs[0][0]
;_ArrayDisplay($r_songs)
;ConsoleWrite($i)
GUICtrlSetData($LV, $r_songs[$i][0])
Next
GUISetState(@SW_SHOW, $Mp3)
While 1
Switch GUIGetMsg()
     Case $GUI_EVENT_CLOSE
         Exit
EndSwitch
WEnd

the other simpler solution is for you to use properly formed ini file with section name

and then use IniReadSection

IniReadSection
Returns a 2 dimensional array where element[n][0] is the key and element[n][1] is the value.
The number of elements returned will be in $result[0][0].

so that you will not have need to recreate array and other things

#include <File.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
#include <GuiListBox.au3>
$songs = IniReadSection ( "Playlist - Copie.ini", "datasection" )
$Mp3 = GUICreate("Mp3 List", 300, 225, -1, -1)
$LV = GUICtrlCreateList("", 5, 100, 290, 130)
_ArrayDisplay($songs)
For $i = 1 To $songs[0][0]
    GUICtrlSetData($LV, $songs[$i][0])
Next
GUISetState(@SW_SHOW, $Mp3)
While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

inifile

[datasection]
3 Days Grace - Now Or Never=E:\Tounes\3 Days Grace - Now Or Never.mp3
3 Doors Down - Kryptonite=E:\Tounes\3 Doors Down - Kryptonite.mp3
30 Seconds To Mars - Battle Of One=E:\Tounes\30 Seconds To Mars - Battle Of One.mp3
30 Seconds To Mars - Beautiful Lie=E:\Tounes\30 Seconds To Mars - Beautiful Lie.mp3
30 Seconds To Mars - Edge of the Earth=E:\Tounes\30 Seconds To Mars - Edge of the Earth.mp3
30 Seconds To Mars - From Yesterday=E:\Tounes\30 Seconds To Mars - From Yesterday.mp3
30 Seconds To Mars - I'll Attack=E:\Tounes\30 Seconds To Mars - I'll Attack.mp3

easy isn it?

Edited by bogQ

TCP server and client - Learning about TCP servers and clients connection
Au3 oIrrlicht - Irrlicht project
Au3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related)



460px-Thief-4-temp-banner.jpg
There are those that believe that the perfect heist lies in the preparation.
Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost.

 

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Thank you it work very well !

I've tried using your second example with IniReadSection but it only show 400 results out of 600+ :ermm:

Edited by Jayson

Share this post


Link to post
Share on other sites

Got it fixed.. It only read 32k chars so i used to exceed that limit.

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
Sign in to follow this  
Followers 0