Page 1 of 1

REDEFINE BTNBMP Within FOR NEXT LOOP

Posted: Sat Jul 27, 2019 12:07 pm
by reds
I have quite a lot of On/Off settings to include so was hoping to set them up using a for next loop
but I'm gettting a bound array error (n=3) on selection

Can this be done if so what do I need to change

Thanks
Peter

Code: Select all

  #include "FiveWin.ch"

function Main()
   LOCAL oBtn[2] 
   LOCAL oDlg   
   LOCAL lOn := {.f.,.t.}
   LOCAL n
   DEFINE DIALOG oDlg  RESOURCE 'DIALOG1'   
    
   FOR n = 1 to 2
   REDEFINE BTNBMP oBtn[n] CENTER NOBORDER UPDATE ID 4029 + n OF oDlg ;
        RESOURCE IIF( lOn[n], 8002,8001 ) ACTION ( lOn[n] := ! lOn[n],::SetImages(IIF( lOn[n], 8002,8001 )),ShowStatus(lOn[n]))     
   NEXT
  
   ACTIVATE DIALOG oDlg  
   
RETURN nil
  FUNCTION ShowStatus(lOn)
   
  @ 6,1 SAY IIF(lOn,"On ","Off") 
   RETURN NIL
 

Re: REDEFINE BTNBMP Within FOR NEXT LOOP

Posted: Sat Jul 27, 2019 4:15 pm
by nageswaragunupudi
Please test this and adapt this logic:

Code: Select all

#include "fivewin.ch"

function Main()

   local aOn   := { .f., .t., .f., .t. }
   local oDlg, oBtn, n
   local nRow, nCol

   DEFINE DIALOG oDlg SIZE 380,150 PIXEL TRUEPIXEL

   nRow  := 40
   nCol  := 40

   for n := 1 to Len( aOn )

      @ nRow, nCol BTNBMP oBtn RESOURCE FWBmpOn(),nil,FWBmpOff() ;
         SIZE 64,64 PIXEL OF oDlg UPDATE 2007 ;
         ACTION aOn[ ::Cargo ] := !aOn[ ::Cargo ]

      WITH OBJECT oBtn
         :Cargo      := n
         :bBmpNo     := { |Self| If( aOn[ ::Cargo ], 1, 3 ) }
      END

      nCol  += 70

   next

   ACTIVATE DIALOG oDlg CENTERED

return nil
 

Re: REDEFINE BTNBMP Within FOR NEXT LOOP

Posted: Mon Jul 29, 2019 6:02 pm
by reds
Many thanks
Peter