Structure Arrays

Just starting out? Need help? Post your questions and find answers here.
orb_505
User
User
Posts: 23
Joined: Wed Apr 05, 2006 2:30 pm

Structure Arrays

Post by orb_505 »

Hi all,

I'm having a bit of a nightmare with this one and was wondering if anyone could help.

I'm making a Structure, within that Structure is a Array:

Code: Select all

Structure Systems
  SystemName.s
  DefaultPath.s
  FileList.s[50]
EndStructure
I then create an Array of that that Structure:

Code: Select all

Dim SystemsList.Systems(20)
I then want the try and populate the FileList Array from an INI file:

Code: Select all

      If ExaminePreferenceKeys()
        While NextPreferenceKey()
          If UCase(PreferenceKeyName()) = "DEFAULTPATH"
            SystemsList(GroupNum)\DefaultPath = PreferenceKeyValue()
          EndIf
          If UCase(Left(PreferenceKeyName(),4)) = "FILE"
            FilesInINI = FilesInINI + 1
            SystemsList(GroupNum)\FileList(FilesInINI) = PreferenceKeyValue()
          EndIf
        Wend
      EndIf
But I keep getting the error 'Garbage at End of Line' for this line SystemsList(GroupNum)\FileList(FilesInINI) = PreferenceKeyValue()

Any help appreciated!

Mark

EDIT:

FYI the INI file looks like this:

Code: Select all

[Type 1 System]
SystemName = Joe Bloggs System
DefaultPath = C:\Program Files\JBloggs\Database\System\
File1 = Names.DAT
File2 = Supply.DBD
File3 = Institution.DAT
    
[Type 2 System]
SystemName = Jimmy System
DefaultPath = C:\
File1 = Names.MDB
File2 = Address.DAT
File3 = TBL.DAT
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Re: Structure Arrays

Post by srod »

You have defined the FileList field as a static array (you have used square brackets). That is fine, PB 4.51 can cope with either static or dynamic arrays within structures. However, because you are using a static array you must persevere with the square brackets.

Code: Select all

SystemsList(GroupNum)\FileList[FilesInINI] = PreferenceKeyValue()
I may look like a mule, but I'm not a complete ass.
orb_505
User
User
Posts: 23
Joined: Wed Apr 05, 2006 2:30 pm

Re: Structure Arrays

Post by orb_505 »

Thank you very much sir!
orb_505
User
User
Posts: 23
Joined: Wed Apr 05, 2006 2:30 pm

Re: Structure Arrays

Post by orb_505 »

On that subjuct of fixed or dynamic arrays. Can you not have a dynamic array in a Structure?

EG:

Code: Select all

Structure Systems
  SystemName.s
  DefaultPath.s
  FileList.s(50)
EndStructure
I've tried it but I get the Garbage error again.
orb_505
User
User
Posts: 23
Joined: Wed Apr 05, 2006 2:30 pm

Re: Structure Arrays

Post by orb_505 »

Forget it, I'm on 4.50 not 4.51 :oops: I'll upgrade
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Re: Structure Arrays

Post by srod »

You'll need something like :

Code: Select all

Structure Systems
  SystemName.s
  DefaultPath.s
  Array FileList.s(50)
EndStructure
I may look like a mule, but I'm not a complete ass.
Post Reply