Use list instead of array

Just starting out? Need help? Post your questions and find answers here.
Allen
User
User
Posts: 92
Joined: Wed Nov 10, 2021 2:05 am

Use list instead of array

Post 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
User avatar
Paul
PureBasic Expert
PureBasic Expert
Posts: 1243
Joined: Fri Apr 25, 2003 4:34 pm
Location: Canada
Contact:

Re: Use list instead of array

Post 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"
Image Image
Allen
User
User
Posts: 92
Joined: Wed Nov 10, 2021 2:05 am

Re: Use list instead of array

Post by Allen »

Paul,

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

Thanks.

Allen
Post Reply