Cancel
Showing results for 
Search instead for 
Did you mean: 

Starting for loop from specific column value

Creator
Creator

Hi,

For a certain method I would like to loop start the for loop from a specific value of a table's first column.

 

The table consist of 3 columns:

Date | Colour | Part Type |

 

As the table has 330.000 rows I would like to only loop a certain part of the table.


The for loop should start from a certain date (for example 27-2-2018) to two days later (for example 20-2-2018)

 

Anyone has a clue on how to perform this?

 

 

2 REPLIES 2

Re: Starting for loop from specific column value

Gears Esteemed Contributor Gears Esteemed Contributor
Gears Esteemed Contributor

you will need to find the right row first, then you can start the loop, in the loop you can check the date and exit the loop at a specific date e.g.

 

var i,r:integer

tableFile.setCursor(1,1)

if tableFile.find({1,1}..{1,*}, str_to_date("27-02-2018"))
  r:=tableFile.cursorY
  for i:=r to tableFile.yDim 
     --do something
     if tableFile[1,i] >= str_to_date("31-03-2018")
        exitLoop
     end
   next
end
Steffen Bangsow
freelance simulation specialist  
web: www.bangsow.eu
mail: steffen@bangsow.net

Re: Starting for loop from specific column value

Siemens Phenom Siemens Phenom
Siemens Phenom

Hello,

 

your could try using something like this:

 

-- sort the list "YourTable" in ascending order for the dates
YourTable.sort(1,"up")

--search for your start date and end date if you don`t know yet where they are
var start_date:date :=str_to_date("30.11.2017")
var end_date: date :=str_to_date("12.01.2018")


for var i := 1 to 333000
		if YourTable[1,i]=start_date --set value for your start index
			Start_RowIndex:=i
			exitloop
		end
next

for var i := Start_RowIndex to 333000
		if YourTable[1,i]=end_date --set value for your end index
			End_RowIndex:=i
			exitloop
		end
next

-- start the for loop through your values in the desired range 

for var i := Start_RowIndex to End_RowIndex
	for var j := 2 to 3
		--do some operation on your desired range of columns
	next
next
Kind regards,

Igor
------------------------------------------------------------------------------------------------------
Did you like the answer? Then click the Thumbs Up button.
Did the answer solve your problem? Then accept the answer as solution