Sorting function

All topics on coding 4Dscript in Enterprise Dynamics.
Post Reply
Magus
Posts: 1
Joined: Wednesday 04 March, 2015 - 17:43

Sorting function

Post by Magus »

I'm trying to build up a code that will act as a sorter based on the name of the products passing though. I was going to run it off a chain of If commands, however this isn't working that well (it's based of code from output choices depending on the atom name)

Code: Select all

if (
	CompareText(Name(Rank(1,c)),[base]),
	1,
	if (
		CompareText(Name(Rank(1,c)),[top]),
		2,
		))
		
Is it possible to run the command so that you can look up in a table the name, and then send it to an output based on its location i the table. i.e. if the name is in (1,1) then it will sent to channel specified in (1,2) etc going down.
User avatar
HarryBunnik
Posts: 362
Joined: Monday 07 February, 2011 - 11:22

Re: Sorting function

Post by HarryBunnik »

Ha Magus,

Yes, that is possible, if your create a table and use the aliases, you can refer to it (I created a refTable in the code below for that). Then you can loop over the table, until you find the corresponding name and use the defined channel. So something like:

Code: Select all

Do(
  var([valRowCount], vbValue, 1), 
  
  LoopUntil(
    CompareText(cell(valRowCount, 1, refTable), name(first(c))) = 1, 
    valRowCount := valRowCount + 1
    nRows(refTable)
  ), 
  Cell(valRowCount , 2, refTable)
)
I hope this helps you further!

Cheers,

Harry
Post Reply