FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour AEVAL multidimentional array
Posts: 1195
Joined: Mon Oct 17, 2005 05:41 AM
AEVAL multidimentional array
Posted: Tue May 13, 2025 08:54 AM

Hi,

Is is possible to aeval a multidimentional array, or do I have to make a combination of a loop and aeval.

I want to execute a function on all elements of a multidimentional array.

Thank you

Regards,

Marc



FWH32+xHarbour | FWH64+Harbour | BCC | DBF | ADO+MySQL | ADO+MariaDB | ADO+SQLite
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: AEVAL multidimentional array
Posted: Tue May 13, 2025 09:06 AM

Dear Marc,

How is your array ?

What do you need ?

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 1195
Joined: Mon Oct 17, 2005 05:41 AM
Re: AEVAL multidimentional array
Posted: Tue May 13, 2025 09:22 AM
Antonio,

Here is an example of the array. The normal one is much bigger
"E1345";"DI";"DIGACQA";"DI";"I_E1345"
"F1305";"GO";"DEVCTLA";"DI";"I_F1305GO
"F1305";"GT";"DEVCTLA";"DI";"I_F1305GT"
I want to perform a function on each element.
For example remove all " at the beginning and end of the element.
Regards,

Marc



FWH32+xHarbour | FWH64+Harbour | BCC | DBF | ADO+MySQL | ADO+MariaDB | ADO+SQLite
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: AEVAL multidimentional array
Posted: Tue May 13, 2025 09:50 AM

AEval( aLines, { | cLine, n | aLines[ n ] := SubStr( cLine, 2 ), aLines[ n ] := SubStr( aLines[ n ], 2, Len( aLines[ n ] ) - 1 ) } )

You can also manage each line as an array:

AEval( aLines, { | cLine, n | aLines[ n ] := hb_ATokens( cLine, ";" ) } )

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 1195
Joined: Mon Oct 17, 2005 05:41 AM
Re: AEVAL multidimentional array
Posted: Tue May 13, 2025 10:08 AM
Antonio,

Sorry for the confusion,but the ';' between each element, is not a real ';' , but a separation between element

So the array is in fact
{ { ' "E1345" '  , ' "DI" ' , ' "DIGACQA" ' , ' "DI" ' ,' "I_E1345" ' } , {' "F1305" ' , ' "GO" ' ,' "DEVCTLA" ' ,' "DI" ' ,' "I_F1305GO" '} , {' "F1305" ' ,' "GT" ' ,' "DEVCTLA" ' ,' "DI" ' ,' "I_F1305GT" '} }
Regards,

Marc



FWH32+xHarbour | FWH64+Harbour | BCC | DBF | ADO+MySQL | ADO+MariaDB | ADO+SQLite
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: AEVAL multidimentional array
Posted: Tue May 13, 2025 10:34 AM

Then it is simpler:

AEval( aLines, { | aLine, n | AEval( aLine, { | cElement, m | ... } ) } )

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 1195
Joined: Mon Oct 17, 2005 05:41 AM
Re: AEVAL multidimentional array
Posted: Tue May 13, 2025 10:49 AM

Thank you Antonio.

Regards,

Marc



FWH32+xHarbour | FWH64+Harbour | BCC | DBF | ADO+MySQL | ADO+MariaDB | ADO+SQLite
Posts: 1195
Joined: Mon Oct 17, 2005 05:41 AM
Re: AEVAL multidimentional array
Posted: Tue May 13, 2025 01:25 PM
Antonio,

I still have a little problem.

I tested it with
 AEval( aLines, { | aLine, n | AEval( aLine, { | cElement, m | cElement := mcsvremove(cElement)  } ) } )
 
 func mcsvremove(vveld)
   vveld = alltrim(vveld)
    msginfo(vveld) //field with "
   if substr(vveld,1,1) = '"'
      vveld = substr(vveld,2,len(vveld)-2)
   endif
   msginfo(vveld) //field without "
return vveld
It execute the mcsvremove() function, but the array is not updated.
If I add a message in mcsvremove(), the funcion removed the "
Regards,

Marc



FWH32+xHarbour | FWH64+Harbour | BCC | DBF | ADO+MySQL | ADO+MariaDB | ADO+SQLite
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: AEVAL multidimentional array
Posted: Tue May 13, 2025 03:27 PM
Marc,

Do it this way:
 AEval( aLines, { | aLine, n | AEval( aLine, { | cElement, m | aLines[ n ][ m ] := mcsvremove(cElement)  } ) } )
 
 func mcsvremove(vveld)
   vveld = alltrim(vveld)
    msginfo(vveld) //field with "
   if substr(vveld,1,1) = '"'
      vveld = substr(vveld,2,len(vveld)-2)
   endif
   msginfo(vveld) //field without "
return vveld
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 1195
Joined: Mon Oct 17, 2005 05:41 AM
Re: AEVAL multidimentional array
Posted: Tue May 13, 2025 06:12 PM
Antonio,

Then I get this compile-error.
Error E0005  Outer codeblock variable is out of reach: 'N'
Regards,

Marc



FWH32+xHarbour | FWH64+Harbour | BCC | DBF | ADO+MySQL | ADO+MariaDB | ADO+SQLite
Posts: 104
Joined: Tue Feb 09, 2021 04:20 PM
Re: AEVAL multidimentional array
Posted: Tue May 13, 2025 08:35 PM
Try This
FOR EACH aList2 IN aList
   FOR EACH xItem IN aList2
      callfunction( @xItem )
   NEXT
NEXT

José M. C. Quintas Brazil

gtwvg, fivewin 25.12, hwgui, mingw 15.2 (32 bits)

Posts: 1195
Joined: Mon Oct 17, 2005 05:41 AM
Re: AEVAL multidimentional array
Posted: Wed May 14, 2025 07:29 AM

José,

That's how I did it now, but I was wondering that with aeval it may be faster...

Regards,

Marc



FWH32+xHarbour | FWH64+Harbour | BCC | DBF | ADO+MySQL | ADO+MariaDB | ADO+SQLite
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: AEVAL multidimentional array
Posted: Wed May 14, 2025 07:40 AM

Marc,

AEval() should be faster, you may compare them:

local p

AEval( aLines, { | aLine, n | p := n, AEval( aLine, { | cItem, m | aLines[ p ][ m ] := YourFunction( cItem ) } ) } )

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 1195
Joined: Mon Oct 17, 2005 05:41 AM
Re: AEVAL multidimentional array
Posted: Wed May 14, 2025 08:10 AM
Antonio,

Now it's working :D

I will try the speed-difference with a large array.

Thank you
Regards,

Marc



FWH32+xHarbour | FWH64+Harbour | BCC | DBF | ADO+MySQL | ADO+MariaDB | ADO+SQLite
Posts: 104
Joined: Tue Feb 09, 2021 04:20 PM
Re: AEVAL multidimentional array
Posted: Wed May 14, 2025 04:17 PM
Sometimes you need to think about fucture.
Source code is to you, not to the computer.
May be you need update the code for a long time, and may be next year you have work to remember what you do.
But sometimes speed is more important.

Last days I do this, using hb_AScan() inside hb_ASCan()
Once hb_AScan() process each element, may be could do a Eval() or AEval()
   LOCAL aNoTestList := { ;
      { "no check", "demoall.prg", "testsamples.prg" }, ;
      { "MDI", "a.prg", "testmdi.prg", "testrtf.prg", "demomdi.prg" }, ;
      { "utility?", "buildpelles.prg", "dbview.prg" }, ;
      { "multithead", "demomenumt.prg" }, ;
      { "window", "demoonother.prg" }, ;
      { "postgress", "grid_2.prg", "grid_3.prg" }, ;
      { "console", "helloworld.prg" }, ;
      { "undefined", "propsh.prg", "tststconsapp.prg", "helpstatic.prg", ;
         "tstprdos.prg", "winprn.prg", "testalert.prg", "pseudocm.prg", ;
         "bincnts.prg", "bindbf.prg", "hexbincnt.prg" }, ;
      { "bug", "tstscrlbar.prg", "helpdemo.prg" } }

   aList := Directory( "*.prg" )      
   FOR EACH aFile IN aList
      IF hb_AScan( aNoTestList, { |a| hb_AScan( a, { |b| ;
         b == Lower( aFile[1] ) } ) != 0 } ) != 0
         LOOP
      ENDIF      
      ...
NEXT

José M. C. Quintas Brazil

gtwvg, fivewin 25.12, hwgui, mingw 15.2 (32 bits)

Continue the discussion