[DONE] Adding items from a file to a ListIconGadget,

Just starting out? Need help? Post your questions and find answers here.
PresFox
User
User
Posts: 33
Joined: Sat Jan 19, 2008 9:30 am

[DONE] Adding items from a file to a ListIconGadget,

Post by PresFox »

Hello,

I am trying to populate a listicongadget from a file.

This is the code i am using:

Code: Select all

Procedure populate_list()

  If ReadFile(0, "Landers.dat")   ; if the file could be read, we continue...
    While Eof(0) = 0           ; loop as long the 'end of file' isn't reached
      landers$ = ReadString(0)
      ; explode the string
      
      AddGadgetItem(#ListIcon_1,-1,landers$)
           
    Wend
    CloseFile(0)               ; close the previously opened file
  Else
    MessageRequester("Information","Couldn't open the file!")
  EndIf

  EndProcedure
The procedure works, but it loops endlessly, instead of stopping at the end of the file, showing the same line over and over again. Why is it doing this?
Last edited by PresFox on Sat Apr 03, 2010 6:27 pm, edited 1 time in total.
User of PB 4.41 - x86
On Windows 7
Intel Core I5 2.26GHZ
8 GB RAM
ATI Mobility Radeon HD 5650
User avatar
Michael Vogel
Addict
Addict
Posts: 2797
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Re: Adding items from a file to a ListIconGadget, endless lo

Post by Michael Vogel »

Your code looks fine for me, so maybe the problem is in your text file?
Just add a debug ":"+landers$+":" after reading from the file to see, what kind of data will be read from the file...

Michael
PresFox
User
User
Posts: 33
Joined: Sat Jan 19, 2008 9:30 am

Re: Adding items from a file to a ListIconGadget, endless lo

Post by PresFox »

debug also shows a endless row of the same (single) line in the file
User of PB 4.41 - x86
On Windows 7
Intel Core I5 2.26GHZ
8 GB RAM
ATI Mobility Radeon HD 5650
PresFox
User
User
Posts: 33
Joined: Sat Jan 19, 2008 9:30 am

Re: Adding items from a file to a ListIconGadget, endless lo

Post by PresFox »

This was my mistake, i put a call to the procedure in the main loop, so it was called over and over again

works fine now
User of PB 4.41 - x86
On Windows 7
Intel Core I5 2.26GHZ
8 GB RAM
ATI Mobility Radeon HD 5650
Post Reply