Cancel
Showing results for 
Search instead for 
Did you mean: 

How to read in values from txt file

Creator
Creator

Hi Community

I am new to Tecnomatix Plant Simulation (TPS). I am using TPS 11.2.1.

I have the following problem or question:

I created an inventory control model like seen in the image:

Inventory model.png

I want to know how to read in values for ReorderPoint and ReorderQuantity by using the method ReadFile and the FileInterface.

 

Currently the only code in the ReadFile method is:

is
do
	InitValuesForModel.open;

--Need code here :-)
InitValuesForModel.close; end;

I am open to any suggestions. The text file InitValuesForModel.txt currently contains: 10000;20000; 

where 10000 is the ReorderPoint value and 20000 the ReorderQuantity value which needs to be assigned (canceling out the old values).

 

The WriteFile method will be required to write to the file ExitValuesForModel.txt in the following format:

10000;20000;<ServiceLevelValue>

 

Attached is my model.

Any help would be appreciated.

 

8 REPLIES

Re: How to read in values from txt file

Siemens Phenom Siemens Phenom
Siemens Phenom

Hello Hopla,

 

the easiest solution is to use a Table object and the method 'readFile' of the table.

 

You can configure the table so that the ';' is a column seperator. This way you will get two columns with the data from your text file.

 

Regards,

Ralf

Regards,

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

Re: How to read in values from txt file

Creator
Creator

Thank you for the quick reply Ralf!

Ok so this is the coding i have for the ReadFile method:

is
	i:integer; count:integer;
	Value:string;
do
	FileInterface.open;
	i:=1;
	count:=1;

	while not FileInterface.eof loop
		Value:= FileInterface.readLn;
		ImportedValues[1,1]:=Value;
		
	end;
	
	FileInterface.close;
end;

 How do i code it to split values at ";" into different columns?

Re: How to read in values from txt file

Siemens Phenom Siemens Phenom
Siemens Phenom

Just set the column seperator of the list to semicolon:

 

ListTextFormat.png

Regards,

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

Re: How to read in values from txt file

Creator
Creator

It is set to semicolon and still prints the values in same cell:

 

Tecno.jpg

 

Isn't it something to do with the codeof the method? 

is
	i:integer; count:integer;
	Value:string;
do
	
	FileInterface.open;
	i:=1;
	count:=1;

	while not FileInterface.eof loop
		
		Value:= FileInterface.readLn;
		ImportedValues[1,1]:=Value;
		
	end;
	
	FileInterface.close;
end;

 Thanx for all the help so far!

 

Re: How to read in values from txt file

Siemens Phenom Siemens Phenom
Siemens Phenom

You should just use the following code:

 

ImportedValues.readFile("Name of your file");

 Regards,

Ralf

Regards,

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

Re: How to read in values from txt file

Creator
Creator

Ok so this is what i used:

is
	i:integer; count:integer;
	Value:string;
do
	--Read in values from textfile
	FileInterface.open;	

		ImportedValues.readFile("InitValuesForModel.txt");
	
	FileInterface.close;
end;

 Then i recieve the error:

Error.png

Permission denied?

Re: How to read in values from txt file

Siemens Phenom Siemens Phenom
Siemens Phenom

Just remove the lines FileInterface.open and FileInterface.close.

 

The permission is denied because the file is already opened in the FileInterface object.

 

If you use the readFile method of the table you don't need the FileInterface object at all.

Regards,

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

Re: How to read in values from txt file

Creator
Creator

Ralf Thanx a million for your help!!!