For, While and Repeat

Just starting out? Need help? Post your questions and find answers here.
Ajm
Posts: 31
Joined: Wed Aug 26, 2015 1:52 pm

For, While and Repeat

Post by Ajm »

Hi,

Can anyone tell me why this is not working in version 1.10. It was working in 1.02. Is it a bug?

The loop within the SelectAllDocs and DeSelectAllDocs procedures don't get past the first iteration.

I have tried a for loop, while loop and repeat loop. They all have the same result.

Code: Select all

Procedure SelectAllDocs()
    Debug "Count of items: " + Str(CountGadgetItems(1))
    
    x = CountGadgetItems(1) 
    
    For k = 0 To x - 1
        Debug "Loop: " + Str(k)
        SetGadgetItemState(1,k,#PB_ListIcon_Checked)  
    Next
        
EndProcedure


Procedure DeSelectAllDocs()
    
    Debug "Count of items: " + Str(CountGadgetItems(1))
    
    x = CountGadgetItems(1) 
    For k = 0 To CountGadgetItems(1) - 1
        Debug "Loop: " + Str(k)
        SetGadgetItemState(1,k,0)  
    Next
        
EndProcedure

Procedure GadgetEvent()
  GadgetID=EventGadget()

  Select GadgetID
    Case 2
      SelectAllDocs()
    Case 3
      DeSelectAllDocs()
  EndSelect
EndProcedure

; Shows possible flags of ListIconGadget in action...
  If OpenWindow(0, 0, 0, 640, 300, "ListIconGadgets", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
      ; left column
      TextGadget    (0,  300, 10, 300, 20, "ListIcon with Checkbox", #PB_Text_Center)
      ListIconGadget(1,  10, 20, 620, 230, "Column 1", 100, #PB_ListIcon_CheckBoxes)  ; ListIcon with checkbox
      For b = 2 To 4                                                                  ; add 3 more columns to each listicon
          AddGadgetColumn(1, b, "Column " + Str(b), 100)
      Next
      For b = 0 To 7          ; add 4 items to each line of the listicons
          AddGadgetItem(1, b, "Item 1"+Chr(10)+"Item 2"+Chr(10)+"Item 3"+Chr(10)+"Item 4")
      Next
      
      ButtonGadget(2, 10, 260, 100, 20, "Select All")
      ButtonGadget(3, 130, 260, 100, 20, "DeSelect All")
      
      BindEvent(#PB_Event_Gadget,@GadgetEvent())
      
  EndIf
Regards

Andy
User avatar
Peter
Posts: 1197
Joined: Mon Feb 24, 2014 10:17 pm
Location: 127.0.0.1:9080
Contact:

Re: For, While and Repeat

Post by Peter »

it looks like a bug. Calling SetGadgetItemState() will cause an error:
Uncaught TypeError: r.M is not a function
Greetings ... Peter
User avatar
T4r4ntul4
Posts: 132
Joined: Wed May 21, 2014 1:57 pm
Location: Netherlands
Contact:

Re: For, While and Repeat

Post by T4r4ntul4 »

it has nothing to do with the for while repeat loop i think, if you try this: its still not working:

Code: Select all

Procedure SelectAllDocs()
    Debug "Count of items: " + Str(CountGadgetItems(1))
   
;     x = CountGadgetItems(1)
;    
;     For k = 0 To x - 1
;         Debug "Loop: " + Str(k)
;         SetGadgetItemState(1,k,#PB_ListIcon_Checked) 
;     Next
    
    SetGadgetItemState(1,0,#PB_ListIcon_Checked) 
    SetGadgetItemState(1,1,#PB_ListIcon_Checked) 
    SetGadgetItemState(1,2,#PB_ListIcon_Checked)

EndProcedure
User avatar
T4r4ntul4
Posts: 132
Joined: Wed May 21, 2014 1:57 pm
Location: Netherlands
Contact:

Re: For, While and Repeat

Post by T4r4ntul4 »

for some reason this is working. except that if you deselect it that all the rows stay blue. but the checkboxes are working now:

Code: Select all

Procedure SelectAllDocs()
    Debug "Count of items: " + Str(CountGadgetItems(1))
   
    x = CountGadgetItems(1)
  
    For k = 0 To x - 1
        Debug "Loop: " + Str(k)
        SetGadgetItemState(1,k,#PB_ListIcon_CheckBoxes | #PB_ListIcon_Checked)
    Next
   
EndProcedure


Procedure DeSelectAllDocs()
   
    Debug "Count of items: " + Str(CountGadgetItems(1))
   
    x = CountGadgetItems(1)
    For k = 0 To CountGadgetItems(1) - 1
        Debug "Loop: " + Str(k)
        SetGadgetItemState(1,k,#PB_ListIcon_CheckBoxes) 
    Next

EndProcedure
Ajm
Posts: 31
Joined: Wed Aug 26, 2015 1:52 pm

Re: For, While and Repeat

Post by Ajm »

Peter wrote:it looks like a bug. Calling SetGadgetItemState() will cause an error:
Uncaught TypeError: r.M is not a function
Greetings ... Peter
Hi Peter,

How do you see these errors from the JavaScript?
Regards

Andy
the.weavster
Posts: 229
Joined: Sat Mar 01, 2014 3:02 pm

Re: For, While and Repeat

Post by the.weavster »

Ajm wrote:How do you see these errors from the JavaScript?
ctrl + shift + j works for most browsers ;)
Post Reply