Page 1 of 1

Posted: Wed Sep 04, 2002 1:25 pm
by BackupUser
Restored from previous forum. Originally posted by Fangbeast.

Is there a way of synchronising (easily) a ListIconGadget and a Linked list for all sorts of operations?

I have 3 loops below which should be able to do the same thing in one but I can't get it right.

First loop marks items in a linked list according to what items are tagged in the display (content()\tag). Second loop then deletes a file on disk according to the filename in Content()\diskfile and then deletes the tagged record itself. Third loop then deletes the tagged items in the display itself.

There has got to be a better way of doing this but my brain has left me tonight and I need help please anyone :):)

Code: Select all

 For Loopy = 0 To CountGadgetItems(#ListBox)
    If GetGadgetItemState(#ListBox, Loopy) & #PB_ListIcon_Checked
      SelectElement(content(), Loopy)
      content()\tag = 1
    EndIf
  Next Loopy

  ResetList(content())
    While NextElement(content())
      If content()\tag = 1
        DeleteFile(content()\diskfile)
        DeleteElement(content())
      EndIf
    Wend

  For Loopy = 0 To CountGadgetItems(#ListBox)
    If GetGadgetItemState(#ListBox, Loopy) & #PB_ListIcon_Checked
        RemoveGadgetItem(#ListBox, Loopy)
        counter - 1
        Loopy - 1
    EndIf
  Next Loopy

[b]

I've now got the below but it crashes. As I said, I don't really know how to do this any other way.

Code: Select all

 listitems = CountGadgetItems(#ListBox) - 1
  ResetList(content())
  
  For Loopy = 0 To listitems
    SelectElement(content(), Loopy)
      If GetGadgetItemState(#ListBox, Loopy) & #PB_ListIcon_Checked
        If content()\record = GetGadgetItemText(content(), Loopy, 0)
          DeleteFile(content()\diskfile)
          DeleteElement(content())
          RemoveGadgetItem(#ListBox, Loopy)
          counter - 1
          Loopy = Loopy - 1
          PreviousElement(content())
          StatusBarText(#MyStatusBar, 0, "Deleting " + content()\diskfile, 0)
          StatusBarText(#MyStatusBar, 1, "Files:  " + Str(counter), 0)
        EndIf
      EndIf
  Next Loopy
[/b]

Posted: Thu Sep 05, 2002 5:52 am
by BackupUser
Restored from previous forum. Originally posted by Danilo.

This should be your 3 loops in 1:

Code: Select all

Loopy = CountGadgetItems(#ListBox) - 1 SelectElement(content(),Loopy)
 Repeat
     If GetGadgetItemState(#ListBox, Loopy) & #PB_ListIcon_Checked
        RemoveGadgetItem(#ListBox, Loopy)
        DeleteFile(content()\diskfile)
        DeleteElement(content())
     EndIf
     Loopy - 1
     SelectElement(content(),Loopy)
 Until Loopy = -1
Your bold edit code contains different stuff ( content()\record )
and i dont know your whole code, so i cant say more.

cya,
...Danilo
(registered PureBasic user)

Posted: Thu Sep 05, 2002 11:16 am
by BackupUser
Restored from previous forum. Originally posted by Fangbeast.
Originally posted by Danilo

This should be your 3 loops in 1:

Your bold edit code contains different stuff ( content()\record )
and i dont know your whole code, so i cant say more.

cya,
...Danilo
(registered PureBasic user)
Thanks Danilo, works great.


Fangles