FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Simple conversion with array gives me problems
Posts: 1487
Joined: Tue Jun 14, 2016 07:51 AM
Simple conversion with array gives me problems
Posted: Fri Jul 28, 2017 02:58 PM
I was looking to make the following menu (popup) more dynamic.
For a test I made a 2 dim array (menuitem, and the return value). Later will get this from database into a array.

Always when I touch arrays in combination with this kind of program rules, i spend hours looking for the correct syntax :-)

If I leave out the -1 in the for next loop, i even get a bound error.

All this is basic, but It won't pop it..... (bad day)

Code (fw): Select all Collapse
static function TrainingMenu( ocol )
   local oPop, cTemp
   local aTrainingen:=  { ;
   { "&Aanwezig"     , "A" }, ; // 1
   { "&Ziek"         , "Z" }, ; // 1
   { "&Kwetsuur"     , "K" }, ; // 1
   { "&Schorsing"    , "S" }, ; // 1
   { "&Verlof"       , "V" }, ; // 1
   { "&Traint alleen", "T" }, ; // 1
   { "E&xamen"       , "X" }, ; // 1
   { "Niet &fit"     , "F" }, ; // 1
   { "&Clear"        , "C " }}   // 1

   MENU oPop POPUP 2007

     for i = 1 to len(aTrainingen)-1

      cTemp = aTrainingen[i,2]

//      MENUITEM aTrainingen[i,1] BLOCK { || oCol:varput("A"),oCol:SetFocus() }  // is working, but not dynamic... always A with is logic.
//      MENUITEM aTrainingen[i,1] BLOCK ( oCol:varput(cTemp),oCol:SetFocus() )   // shows always last item
      MENUITEM aTrainingen[i,1] ACTION ( oCol:varput(aTrainingen[i,2]),oCol:oBrw:SetFocus() ) // shows menu, always last item

     next

/*
      MENUITEM "&Aanwezig" ;
         ACTION ( oCol:varput("A"),oCol:SetFocus() )
      MENUITEM "&Ziek" ;
         ACTION ( oCol:varput("Z"),oCol:SetFocus() )
      MENUITEM "&Kwetsuur" ;
         ACTION ( oCol:varput("K"),oCol:SetFocus() )
      MENUITEM "&Schorsing" ;
         ACTION ( oCol:varput("S"),oCol:SetFocus() )
      MENUITEM "&Verlof" ;
         ACTION ( oCol:varput("V"),oCol:SetFocus() )
      MENUITEM "&Traint alleen maar" ;
         ACTION ( oCol:varput("T"),oCol:SetFocus() )
      MENUITEM "E&xamen" ;
         ACTION ( oCol:varput("X"),oCol:SetFocus() )
      MENUITEM "Niet &Fit" ;
         ACTION ( oCol:varput("F"),oCol:SetFocus() )
      MENUITEM "&Clear" ;
         ACTION ( oCol:varput(" "),oCol:SetFocus() )
      */

   ENDMENU

return oPop
Marc Venken

Using: FWH 23.08 with Harbour
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: Simple conversion with array gives me problems
Posted: Fri Jul 28, 2017 05:36 PM

Probably you have to use detached locals. Please provide a compilable sample showing the error and I will show you how to fix it.

EMG

Posts: 1487
Joined: Tue Jun 14, 2016 07:51 AM
Re: Simple conversion with array gives me problems
Posted: Fri Jul 28, 2017 06:34 PM
Here is the sample.

So, the value in the second part of the array aTrainingen should be selected.

Code (fw): Select all Collapse
#include "fivewin.ch"

function Main()

   local oDlg, oBrw1

   USE CUSTOMER NEW ALIAS CUST1 SHARED

   DEFINE DIALOG oDlg SIZE 800,800 PIXEL TRUEPIXEL ;
      TITLE "Forum Tests"

   aVelden :=  { ;
   { "First"  , "First"         ,nil, 125 }, ; // 1
   { "Last"   , "Last"          ,nil, 125 }, ; // 3
   { "State"  , "State"         ,nil,  50 }}

   @  20,20 XBROWSE oBrw1 SIZE -20,380 PIXEL OF oDlg ;
      DATASOURCE "CUST1";
      COLUMNS aVelden;
      AUTOSORT CELL LINES NOBORDER FOOTER FASTEDIT

   oBrw1:lColChangeNotify  := .t.

   WITH OBJECT oBrw1
      WITH OBJECT :STATE
         :nEditType     := EDIT_GET
         :bPopUp        := { |o| TrainingMenu( o ) }
      END
   END

   oBrw1:CreateFromCode()

   ACTIVATE DIALOG oDlg CENTERED

return nil

//----------------------------------------------------------------------------//
static function TrainingMenu( ocol )
   local oPop, cTemp, i
   local aTrainingen:=  { ;
   { "&Aanwezig"     , "A" }, ; // 1
   { "&Ziek"         , "Z" }, ; // 1
   { "&Kwetsuur"     , "K" }, ; // 1
   { "&Schorsing"    , "S" }, ; // 1
   { "&Verlof"       , "V" }, ; // 1
   { "&Traint alleen", "T" }, ; // 1
   { "E&xamen"       , "X" }, ; // 1
   { "Niet &fit"     , "F" }, ; // 1
   { "&Clear"        , "C " }}   // 1

   //xbrowser(aTrainingen)

   MENU oPop POPUP 2007

     for i = 1 to len(aTrainingen) -1

      cTemp = aTrainingen[i,2]

//      MENUITEM aTrainingen[i,1] BLOCK { || oCol:varput("A"),oCol:SetFocus() }  // is working, but not dynamic... always A
//      MENUITEM aTrainingen[i,1] BLOCK ( oCol:varput(cTemp),oCol:SetFocus() )   // shows always last item
      MENUITEM aTrainingen[i,1] ACTION ( oCol:varput(aTrainingen[i,2]),oCol:oBrw:SetFocus() ) // shows menu, always last item

     next

/*
      MENUITEM "&Aanwezig" ;
         ACTION ( oCol:varput("A"),oCol:SetFocus() )
      MENUITEM "&Ziek" ;
         ACTION ( oCol:varput("Z"),oCol:SetFocus() )
      MENUITEM "&Kwetsuur" ;
         ACTION ( oCol:varput("K"),oCol:SetFocus() )
      MENUITEM "&Schorsing" ;
         ACTION ( oCol:varput("S"),oCol:SetFocus() )
      MENUITEM "&Verlof" ;
         ACTION ( oCol:varput("V"),oCol:SetFocus() )
      MENUITEM "&Traint alleen maar" ;
         ACTION ( oCol:varput("T"),oCol:SetFocus() )
      MENUITEM "E&xamen" ;
         ACTION ( oCol:varput("X"),oCol:SetFocus() )
      MENUITEM "Niet &Fit" ;
         ACTION ( oCol:varput("F"),oCol:SetFocus() )
      MENUITEM "&Clear" ;
         ACTION ( oCol:varput(" "),oCol:SetFocus() )
      */

   ENDMENU

return oPop
Marc Venken

Using: FWH 23.08 with Harbour
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Simple conversion with array gives me problems
Posted: Fri Jul 28, 2017 06:35 PM
Code (fw): Select all Collapse
   MENU oPop POPUP 2007

      for i = 1 to len( aTrainingen )

         //MENUITEM oItem ACTION oCol:VarPut( oMenuItem:Cargo )  // wrong
         MENUITEM oItem PROMPT aTrainingen[ i, 1 ] ACTION oCol:VarPut( oMenuItem:Cargo ) 
          oItem:Cargo := aTrainingen[ i, 2 ]
      
      next

   ENDMENU
Regards



G. N. Rao.

Hyderabad, India
Posts: 274
Joined: Fri Apr 04, 2008 01:25 PM
Re: Simple conversion with array gives me problems
Posted: Fri Jul 28, 2017 07:25 PM
Mr. Rao, Marc

with that code I get an error message:
Error description: Error BASE/1005 Class: 'NIL' has no property: CARGO

in the line
Code (fw): Select all Collapse
oItem:Cargo := aTrainingen[ i, 2 ]


but this seems to be working:

Code (fw): Select all Collapse
   MENU oPop POPUP 2007

        for i = 1 to len(aTrainingen) 
            MENUITEM aTrainingen[i,1] BLOCK Blockify(i, oCol, aTrainingen)
        next

   ENDMENU


with

Code (fw): Select all Collapse
STATIC FUNCTION Blockify(i, oCol, aTrainingen)
return { || oCol:varput(aTrainingen[i,2]),oCol:oBrw:SetFocus() }
Best Regards,

Gilbert Kuhnert
CTO Software GmbH
http://www.ctosoftware.de
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Simple conversion with array gives me problems
Posted: Fri Jul 28, 2017 07:39 PM
with that code I get an error message:
Quote:
Error description: Error BASE/1005 Class: 'NIL' has no property: CARGO


Sorry. Please use my corrected code.

Well, your code anyway has to work, because it uses detached locals. I wanted to provide a much simpler solution.
Regards



G. N. Rao.

Hyderabad, India
Posts: 1487
Joined: Tue Jun 14, 2016 07:51 AM
Re: Simple conversion with array gives me problems
Posted: Sat Jul 29, 2017 09:36 AM

Thanks for all the solutions.

I go for the easy of Mr. Rao :wink:

But thanks for you all, because now, and afther looking for the "detached locals technicque" in the forum, I know where the problem came from, and knowing the problem is half of the work done !!!

Marc Venken

Using: FWH 23.08 with Harbour

Continue the discussion