Reading Tickboxes in a ListIconGadget

Just starting out? Need help? Post your questions and find answers here.
Maximus_Primal
User
User
Posts: 12
Joined: Sat Dec 18, 2004 7:01 pm
Location: England, UK
Contact:

Reading Tickboxes in a ListIconGadget

Post by Maximus_Primal »

I have a problem reading the checkboxes within a ListIconGadget for some reason. The ListIconGadget is populated depending on the contents of a file read beforehand. As shown below (The variable EntrySelect is set from an unshown ListIconGadget and 1 is added to it's vaule as a ListIconGadget starts at 0 and not 1, this way the program knowns which set of options to display).

Code: Select all


TextGadget(#Text_19, 60, 290, 90, 30, "Accessories Included", #PB_Text_Center)
SetGadgetFont(#Text_19, FontID3)
ListIconGadget(#ListIcon_2, 50, 320, 110, 190, "Accessory", 100, #PB_ListIcon_CheckBoxes | #PB_ListIcon_GridLines)
 
 TextGadget(#Text_21, 600, 290, 110, 30, "Variant Information", #PB_Text_Center)
      SetGadgetFont(#Text_21, FontID3)
      ListIconGadget(#ListIcon_3, 600, 320, 110, 190, "Variant", 100, #PB_ListIcon_CheckBoxes | #PB_ListIcon_GridLines)

Dim Accessories.s (30,20)
Dim AccList.b (30)

If ReadFile (10,"C:\Program Files\PureBasic\TF Database\VS\Teletran\DBAccList.tdb")

  Repeat
  
    Rd$=ReadString()
  
      If Left(Rd$,2)="--"
  
        For Cx=Count2 To 20
          Accessories(Count1,Cx)=""
        Next Cx  

        Count1 = Count1+1
        Count2 = 1
    
      Else
        Accessories (Count1,Count2)=Rd$
        AccList (Count1) = Count2
        Count2 = Count2+1
      EndIf
  
  Until Eof(10)
  
    CloseFile (10)
EndIf

EntrySelect=EntrySelect+1

Accs=0
For Count=2 To AccList(EntrySelect)

If Left(Accessories(EntrySelect,Count),4)="Var:"
  t$=Mid(Accessories(EntrySelect,Count),5, Len(Accessories(EntrySelect,Count)))
  AddGadgetItem (#ListIcon_3, -1, t$)
Else
  AddGadgetItem (#ListIcon_2, -1, Accessories(EntrySelect,Count) )
  Accs=Accs+1
EndIf

Next Count
The file which is read looks like this:
  • Jazz
    Gun
    Launcher
    Missile 1
    Missile 2
    Missile 3
    Var:Rub Symbol
    Var:No Rub Symbol
    --
    Laserbeak
    Var:Rub Symbol
    Var:No Rub Symbol
    --
This populates the list perfectly. Now to read which ones are ticked or not I used this:

Code: Select all

Acc$=""

If Accs>0
  For Cnt=1 To Accs
    Result = GetGadgetItemState(#ListIcon_2, Cnt)
    If Result & #PB_ListIcon_Checked
      Acc$=Acc$+"A"
        Else
      Acc$=Acc$+"O"
    EndIf
  Next Cnt
EndIf

Debug "Acc$ = "+Acc$
For some reason the tickboxes are not read right. If there are 5 options available (as shown in the example) the last one always get an "A" for ticked even when it isn't (e.g Acc$="OOOOA" and not "OOOOO" if no boxes are ticked).

What have I done wrong? I found out how to read tickboxes from an example in the PureBasic Code Archive and though it should work as I have done.

Hopefully there is enough information there to make sense of what I have done.

Thanks in advance.

Max
Real Power Comes From Sharing With Those Who Think They Have It All!
Pupil
Enthusiast
Enthusiast
Posts: 715
Joined: Fri Apr 25, 2003 3:56 pm

Post by Pupil »

i think the item index start at '0'.
Maximus_Primal
User
User
Posts: 12
Joined: Sat Dec 18, 2004 7:01 pm
Location: England, UK
Contact:

Post by Maximus_Primal »

Pupil wrote:i think the item index start at '0'.
Supprisingly I didn't see what you where getting at until just now as I lay in the bath thought of what you said and realise what a pillock I was and why it doesn't work! :D

Thanks I knew it had to be something stupid I had overlooked.

Max
Real Power Comes From Sharing With Those Who Think They Have It All!
Maximus_Primal
User
User
Posts: 12
Joined: Sat Dec 18, 2004 7:01 pm
Location: England, UK
Contact:

Post by Maximus_Primal »

That fixed it. Thanks! :lol:
Real Power Comes From Sharing With Those Who Think They Have It All!
Post Reply