Bad workaround for code that i can't get working

Bad workaround for code that i can't get working

Postby Marc Venken » Sat Mar 20, 2021 11:54 pm

I tried and tried to get this code working the correct way.

It is probably simple, but i have a bad day i think :twisted:

I have a Xbrowse with a field "NAAM". That field will be splitt into a array to have every single word (hb_aTokens)
Then there will be build btnbmp's for every word. Klikken on one of them will start a xbrowse (filter for that word)

The issues are down in the section : // THE PROBLEM CODE

The buttons label are changes only when it is a xbrowse field (or dbf) and NOT when i simply try to use arrays.
My bad but working solution is to put every word into one dbf-field and show substr's of the field.

The first 3 a build from a loop array and are not working
The second 3 a build in without loop and work.

Why are the arrays not working?

Image

Code: Select all  Expand view


function BrowseSamples()

   local oDlg, oFont, oBold, oMono, oGet, oBrw, i
   local nKnopTop := 100, nKnopLeft := 950, nKnopSpace := 30
   Local aKnoppen:={"","","","","","",""},aKnoppentxt:={"Een","Twee","Drie","Vier","Vijf","Zes","Zeven"}
   Local nTable:= 1
   DEFINE FONT oFont NAME "Segoe UI" SIZE 0,-10
   DEFINE FONT oBold NAME "TAHOMA" SIZE 0,-12 BOLD
   DEFINE FONT oMono NAME "Lucida Console" SIZE 0,-10

   DEFINE DIALOG oDlg SIZE 1600,800 PIXEL TRUEPIXEL FONT oFont ;
      TITLE "Download online catalogus"

   @  90,20 XBROWSE oBrw SIZE 900,-20 PIXEL OF oDlg ;
      DATASOURCE "webshop" ;
      COLUMNS "code", "naam","Groep", "prijs","Korting","Brand", "RefLev","Link" ;
      HEADERS "code", "naam","Groep", "prijs","Kor", "Brand", "RefLev","Link" ;
      COLSIZES 40,      300,   100,      40,    40,     30,      30,     100 ;
      AUTOSORT LINES NOBORDER

   WITH OBJECT oBrw
      :nMarqueeStyle := MARQSTYLE_HIGHLROWRC
      :bChange       := { || oDlg:Update() }
      :lIncrFilter   := .t.
      :bSeek         := { |c| ( oBrw:cAlias )->( BrwFilter( c ) ) }

      :bChange := { || updateknoppen(oBrw,aKnoppentxt),oDlg:update()}

      :CreateFromCode()

   END

   @ 20, 10 SAY TRIM( webshop->naam ) SIZE 860,30 PIXEL OF oDlg CENTER ;
         FONT oBold UPDATE

   @ 60, 20 SAY "Filter containing all words any where" SIZE 300,20 PIXEL OF oDlg

   @ 60,240 SAY oBrw:oSeek PROMPT oBrw:cSeek SIZE 250,20 PIXEL OF oDlg ;
      COLOR CLR_HRED,CLR_YELLOW

   @  90,1200 SAY "CODE" SIZE 260,30 PIXEL OF oDlg CENTER ;
      COLOR CLR_BLACK, nRGB( 231, 242, 255 )

   @ 120,1200 GET oGet VAR webshop->memo SIZE 260,540 PIXEL OF oDlg ;
      MEMO READONLY FONT oMono UPDATE

/*
      for i = 1 to len(aKnoppen)
          @ nKnopTop+(nKnopSpace*I),nKnopLeft BTNBMP aKnoppen[i] OF oDlg SIZE 120, 25 NOBORDER PROMPT aKnoppenTxt[i] 2007 ACTION (;
          SET_SCOPE_Keyword(::cCaption),oDlg:update() ) font oBold CENTER UPDATE
      next
*/


   //  THE PROBLEM CODE

   oDlg:bInit := <||

      //msglist(aKnoppentxt)
      cStr = oBrw:naam:value
      //msginfo(cStr)
      aKnoppentxt = HB_aTokens(cStr," ")
      //msglist(aKnoppentxt)

      */


      for i = 1 to 3
      //@ 40, 40 BTNBMP aKnoppen[ i ] ;
      //  PROMPT { || left(webshop->naam,10)+" : "+aKnoppentxt[i] } ;
      @ nKnopTop+(nKnopSpace*I),nKnopLeft BTNBMP aKnoppen[ i ] ;
               PROMPT { || left(webshop->naam,10)+" : "+aKnoppentxt[i] } ;
               SIZE 240,25 PIXEL OF oDlg 2007 ACTION (SET_SCOPE_Keyword(::cCaption),oDlg:update() ) font oBold CENTER UPDATE
      /*
      @ nKnopTop+(nKnopSpace*I),nKnopLeft BTNBMP aKnoppen[ i ] ;
               PROMPT { || substr(webshop->brand,(I*4),5) } ;
               SIZE 240,25 PIXEL OF oDlg 2007 ACTION (SET_SCOPE_Keyword(::cCaption),oDlg:update() ) font oBold CENTER UPDATE
      */

      next

      @ nKnopTop+(nKnopSpace*5),nKnopLeft BTNBMP aKnoppen[ 4 ] ;
               PROMPT { || alltrim(substr(webshop->memo,1,10)) } ;
               SIZE 240,25 PIXEL OF oDlg 2007 ACTION (SET_SCOPE_Keyword(::cCaption),oDlg:update() ) font oBold CENTER UPDATE

      @ nKnopTop+(nKnopSpace*6),nKnopLeft BTNBMP aKnoppen[ 5 ] ;
               PROMPT { || alltrim(substr(webshop->memo,11,10)) } ;
               SIZE 240,25 PIXEL OF oDlg 2007 ACTION (SET_SCOPE_Keyword(::cCaption),oDlg:update() ) font oBold CENTER UPDATE

      @ nKnopTop+(nKnopSpace*7),nKnopLeft BTNBMP aKnoppen[ 6 ] ;
               PROMPT { || alltrim(substr(webshop->memo,21,10)) } ;
               SIZE 240,25 PIXEL OF oDlg 2007 ACTION (SET_SCOPE_Keyword(::cCaption),oDlg:update() ) font oBold CENTER UPDATE

      */
      //AEval( aKnoppen, { |o| updateknoppen(oBrw) } )

      //oPanel:SetRange()
      return nil
   >

   ACTIVATE DIALOG oDlg CENTERED
   RELEASE FONT oFont, oMono, oBold

return nil


function updateknoppen(obrw,aKnoppentxt)
   cStr = alltrim(oBrw:naam:value)
   aKnoppen = HB_aTokens(cStr," ")
   cTemp = ""
   for i = 1 to len(aKnoppen)
      cStr = PadR( aKnoppen[i], 10 )
      cTemp = cTemp + cStr
   next
   webshop->memo = cTemp
return NIL



 
Marc Venken
Using: FWH 23.04 with Harbour
User avatar
Marc Venken
 
Posts: 1429
Joined: Tue Jun 14, 2016 7:51 am
Location: Belgium

Re: Bad workaround for code that i can't get working

Postby Marc Venken » Sat Mar 20, 2021 11:55 pm

The sample from mr. Rao is working with array !!

Code: Select all  Expand view

#include "fivewin.ch"

function Main()

   local oDlg, oPanel, aBtn[ 2 ], oFont, oBold
   local aPrices := { { 25.40, 45.70 }, { 77.20, 92.34 } }
   local nTable := 1

   DEFINE FONT oFont NAME "TAHOMA" SIZE 0,-22
   DEFINE FONT oBold NAME "VERDANA" SIZE 0,-23 BOLD

   DEFINE DIALOG oDlg SIZE 600,450 PIXEL TRUEPIXEL FONT oFont

   //oPanel   := TScrollPanel():New( 40,40,300,560, oDlg )

   @ 330,100 COMBOBOX nTable ITEMS { "Table-1", "Table-2" } ;
      ON CHANGE oDlg:Update() ;
      SIZE 200,400 PIXEL OF oDlg FONT oBold

   oDlg:bInit := <||

      @ 40, 40 BTNBMP aBtn[ 1 ] ;
               PROMPT { || "FIRST" + CRLF + TRANSFORM( aPrices[ nTable, 1 ], "$ 99.99" ) } ;
               BITMAP "c:\fwh\bitmaps\pngs\image7.png" RIGHT ;
               SIZE 200,100 PIXEL OF oDlg 2007 UPDATE
      @ 40,280 BTNBMP aBtn[ 2 ] ;
               PROMPT { || "SECOND" + CRLF + TRANSFORM( aPrices[ nTable, 2 ], "$ 99.99" ) } ;
               BITMAP "c:\fwh\bitmaps\pngs\image8.png" RIGHT ;
               SIZE 200,100 PIXEL OF oDlg 2007 UPDATE

      AEval( aBtn, { |o| o:oFontBold := oBold } )

      //oPanel:SetRange()
      return nil
   >

   ACTIVATE DIALOG oDlg CENTERED
   RELEASE FONT oFont, oBold

return nil

 
Marc Venken
Using: FWH 23.04 with Harbour
User avatar
Marc Venken
 
Posts: 1429
Joined: Tue Jun 14, 2016 7:51 am
Location: Belgium

Re: Bad workaround for code that i can't get working

Postby nageswaragunupudi » Sun Mar 21, 2021 4:14 am

We can not and should not use a loop variable in the codeblock created inside the loop. If and when that becomes necessary, we need to create the codeblock in a separate function using the principle of detached locals.

Instead, I advise you to create the 3 buttons individually like this:

Code: Select all  Expand view

@ r, c BTNBMP PROMPT { || TOKEN( FIELD->NAAM, nil, 1 ) } .....ACTION ...
@ r, c BTNBMP PROMPT { || TOKEN( FIELD->NAAM, nil, 2 ) } .....ACTION ...
@ r, c BTNBMP PROMPT { || TOKEN( FIELD->NAAM, nil, 3 ) } .....ACTION ...
 


Using TOKEN( text, nil, tokennumber ) is simpler than the way you are using hb_atokens()
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10628
Joined: Sun Nov 19, 2006 5:22 am
Location: India


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 85 guests