Page 1 of 1

Use list instead of array

Posted: Sat Mar 25, 2023 3:17 pm
by Allen
Hi,

I am not familiary with list. In below code, I use dynamic array that I need to redim as needed. If I want to use list, Please advise how to delare the varibles?

Code: Select all

#MaxSongInDir=1
#MaxDir=1

Structure Songs ; store all songs name in an sub directory (Path$)
  Path$
  SongQty.i
  Array SongName$(#MaxSongInDir)
EndStructure

Structure DirInfos ;  store the song info in an parent directory
  TotalSong.i
  TotalDir.i
  Array DirNo.Songs(#MaxDir)
EndStructure

Global Dim RootDir.DirInfos(2)


ReDim RootDir(1)\DirNo(2)
ReDim RootDir(2)\DirNo(1)\SongName$(3)
Thanks

Allen

Re: Use list instead of array

Posted: Sat Mar 25, 2023 3:49 pm
by Paul
Like this??

Code: Select all

Structure Songs ; store all songs name in an sub directory (Path$)
  Path$
  SongQty.i
  List SongName$()
EndStructure

Structure DirInfos ;  store the song info in an parent directory
  TotalSong.i
  TotalDir.i
  List DirNo.Songs()
EndStructure

Global NewList RootDir.DirInfos()


AddElement(RootDir())
RootDir()\TotalSong=2
RootDir()\TotalDir=1
AddElement(RootDir()\DirNo())
RootDir()\DirNo()\Path$="C:\"
RootDir()\DirNo()\SongQty=5
AddElement(RootDir()\DirNo()\SongName$())
RootDir()\DirNo()\SongName$()="S1"
AddElement(RootDir()\DirNo()\SongName$())
RootDir()\DirNo()\SongName$()="S2"

Re: Use list instead of array

Posted: Sun Mar 26, 2023 1:23 am
by Allen
Paul,

Thanks for the example that is I am looking for. I understand list more now.

Thanks.

Allen