Simple conversion with array gives me problems

Simple conversion with array gives me problems

Postby Marc Venken » Fri Jul 28, 2017 2: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 :oops:

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: Select all  Expand view

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:oBrw:SetFocus() }  // is working, but not dynamic... always A with is logic.
//      MENUITEM aTrainingen[i,1] BLOCK ( oCol:varput(cTemp),oCol:oBrw: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:oBrw:SetFocus() )
      MENUITEM "&Ziek" ;
         ACTION ( oCol:varput("Z"),oCol:oBrw:SetFocus() )
      MENUITEM "&Kwetsuur" ;
         ACTION ( oCol:varput("K"),oCol:oBrw:SetFocus() )
      MENUITEM "&Schorsing" ;
         ACTION ( oCol:varput("S"),oCol:oBrw:SetFocus() )
      MENUITEM "&Verlof" ;
         ACTION ( oCol:varput("V"),oCol:oBrw:SetFocus() )
      MENUITEM "&Traint alleen maar" ;
         ACTION ( oCol:varput("T"),oCol:oBrw:SetFocus() )
      MENUITEM "E&xamen" ;
         ACTION ( oCol:varput("X"),oCol:oBrw:SetFocus() )
      MENUITEM "Niet &Fit" ;
         ACTION ( oCol:varput("F"),oCol:oBrw:SetFocus() )
      MENUITEM "&Clear" ;
         ACTION ( oCol:varput(" "),oCol:oBrw:SetFocus() )
      */


   ENDMENU

return oPop

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

Re: Simple conversion with array gives me problems

Postby Enrico Maria Giordano » Fri Jul 28, 2017 5: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
User avatar
Enrico Maria Giordano
 
Posts: 8710
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: Simple conversion with array gives me problems

Postby Marc Venken » Fri Jul 28, 2017 6:34 pm

Here is the sample.

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

Code: Select all  Expand view

#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:oBrw:SetFocus() }  // is working, but not dynamic... always A
//      MENUITEM aTrainingen[i,1] BLOCK ( oCol:varput(cTemp),oCol:oBrw: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:oBrw:SetFocus() )
      MENUITEM "&Ziek" ;
         ACTION ( oCol:varput("Z"),oCol:oBrw:SetFocus() )
      MENUITEM "&Kwetsuur" ;
         ACTION ( oCol:varput("K"),oCol:oBrw:SetFocus() )
      MENUITEM "&Schorsing" ;
         ACTION ( oCol:varput("S"),oCol:oBrw:SetFocus() )
      MENUITEM "&Verlof" ;
         ACTION ( oCol:varput("V"),oCol:oBrw:SetFocus() )
      MENUITEM "&Traint alleen maar" ;
         ACTION ( oCol:varput("T"),oCol:oBrw:SetFocus() )
      MENUITEM "E&xamen" ;
         ACTION ( oCol:varput("X"),oCol:oBrw:SetFocus() )
      MENUITEM "Niet &Fit" ;
         ACTION ( oCol:varput("F"),oCol:oBrw:SetFocus() )
      MENUITEM "&Clear" ;
         ACTION ( oCol:varput(" "),oCol:oBrw:SetFocus() )
      */


   ENDMENU

return oPop

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

Re: Simple conversion with array gives me problems

Postby nageswaragunupudi » Fri Jul 28, 2017 6:35 pm

Code: Select all  Expand view
  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
User avatar
nageswaragunupudi
 
Posts: 10620
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Simple conversion with array gives me problems

Postby gkuhnert » Fri Jul 28, 2017 7: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: Select all  Expand view
oItem:Cargo := aTrainingen[ i, 2 ]


but this seems to be working:

Code: Select all  Expand view
  MENU oPop POPUP 2007

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

   ENDMENU
 


with

Code: Select all  Expand view
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
User avatar
gkuhnert
 
Posts: 274
Joined: Fri Apr 04, 2008 1:25 pm
Location: Aachen - Germany // Kerkrade - Netherlands

Re: Simple conversion with array gives me problems

Postby nageswaragunupudi » Fri Jul 28, 2017 7: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
User avatar
nageswaragunupudi
 
Posts: 10620
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Simple conversion with array gives me problems

Postby Marc Venken » Sat Jul 29, 2017 9: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.04 with Harbour
User avatar
Marc Venken
 
Posts: 1425
Joined: Tue Jun 14, 2016 7:51 am
Location: Belgium


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 17 guests