Cancel
Showing results for 
Search instead for 
Did you mean: 

The last row of a column in a tablefile

Builder
Builder

Hi,

 

How to find the last row of a column in a tablefile. Now I know I can use tablefile.yDim to denote the last row of the entire tablefile, but how can I denote the last row of, e.g., column 2?

 

thanks

10 REPLIES

Re: The last row of a column in a tablefile

Gears Esteemed Contributor Gears Esteemed Contributor
Gears Esteemed Contributor

If you have different number of entries in the columns, you can use the method find to look for the first empty cell (value=void) e.g. for column 2:

 

tableFile.setCursor(2,1);
--look for empty cell
tableFile.find({2,1}..{2,*},void);
local rowNumber:=tableFile.cursorY;

 

 

Steffen Bangsow
freelance simulation specialist  
web: www.bangsow.eu
mail: steffen@bangsow.net

Re: The last row of a column in a tablefile

Gears Esteemed Contributor Gears Esteemed Contributor
Gears Esteemed Contributor

little extension

 

find searches only until tableFile.yDim, if the next empty cell is located in a new row, the method find returns false, so the following extension:

tableFile.setCursor(2,1);
--look for empty cell
if tableFile.find({2,1}..{2,*},void) then
-- below yDim
rowNumber:=tableFile.cursorY;
else
-- new row
rowNumber:=tableFile.YDim+1;
end;

 

Steffen Bangsow
freelance simulation specialist  
web: www.bangsow.eu
mail: steffen@bangsow.net

Re: The last row of a column in a tablefile

Builder
Builder
thanks

Re: The last row of a column in a tablefile

Genius
Genius

This works too, and saves 2 lines of code. lol.

tableFile.setCursor(2,1);
--look for empty cell
if tableFile.find({2,1}..{2,YDim+1},void) then
-- below yDim
rowNumber:=tableFile.cursorY;
end;

 

Re: The last row of a column in a tablefile

Gears Phenom Gears Phenom
Gears Phenom

Well, in that case, you could also drop the IF-clause (because in yDim+1 a VOID will definitely be found) and save another line ^^

tableFile.setCursor(2,1);
tableFile.find({2,1}..{2,tableFile.yDim+1},void)
rowNumber:=tableFile.cursorY;

However, note that you could get into trouble if you have limited your table-dimensions (rows, more specifically) and maxYdim = yDim, I guess you'll get an error when searching to yDim+1 then Smiley Wink

____________________________________________________________
Alex Dilg, Consultant at SimPlan AG (www.SimPlan.de)
This post was good and/or helpful to you? Please provide some Kudos, thank you!

Re: The last row of a column in a tablefile

Genius
Genius

I like the way you think Alex Robot Very Happy

Re: The last row of a column in a tablefile

Genius
Genius

Hello,

There is an attribute to get the specific column Ydim. 

The attribute is 'GetColumnYdim'.

 

Syntax:  <Path>.getColumnYDim(ColumnNumber:<integer>) 

 

Eg.: TableFile.getColumnYdim(1);

Thanks & Best Regards,
Abhilash Sridhar
Mercedes Benz R&D India, Daimler AG

Re: The last row of a column in a tablefile

Gears Phenom Gears Phenom
Gears Phenom
Neat! When did they add this method into the software? Probably with Plant 12.0; I started with Plant 9 and up until 11 this did not exist. Seems I need to read the release notes more carefully ^^
____________________________________________________________
Alex Dilg, Consultant at SimPlan AG (www.SimPlan.de)
This post was good and/or helpful to you? Please provide some Kudos, thank you!

Re: The last row of a column in a tablefile

Genius
Genius

I thought I saw that in the help at one point... but I could not for the life of me, find it!

Thanks!