Jump to content
Developer Wiki and Function Reference Links ×

Reading order of values in txt file


Recommended Posts

Hi,

I'm working on a script that reads a file ( tab delimited ) and rewrites it afterwards.

The issue is, that if I do the following Read(Val1,Val2...) and there is no val1 in the file, the val2 will be stored in Val1 etc..

Is there any way to code past this ? (Besides working with a CSV file and exploding the input)

PROCEDURE Example;
CONST
cTab =  chr(9);
TYPE
SheetCells = STRUCTURE
	A,B,C,D,E,F,G,H,I,J,K,L,M,N,O		:STRING;
END;
VAR
   fileName :STRING; 
   major, minor, maintenance, platform :INTEGER;
i,j	:INTEGER;
SheetData	:DYNARRAY[] OF SheetCells;

BEGIN
   GetVersion(major, minor, maintenance, platform);
   IF platform = 1 THEN BEGIN
       { mac }
   END ELSE BEGIN
	{ windows }
	GetFile(FileName);
   END;
IF NOT DidCancel THEN BEGIN
	{ read }
	open(fileName);
		WHILE NOT EOF(fileName) DO BEGIN
			i:=i+1;
			ALLOCATE SheetData[1..i];
			ReadLn(SheetData[i].A,SheetData[i].B,SheetData[i].C,SheetData[i].D,SheetData[i].E,SheetData[i].F,SheetData[i].G,SheetData[i].H,SheetData[i].I,SheetData[i].J,SheetData[i].K,SheetData[i].L,SheetData[i].M,SheetData[i].N,SheetData[i].O);

		END;
	Close(fileName);

	{ rewrite }
	ReWrite(fileName);
		FOR j:=1 TO i DO BEGIN
			WriteLn(SheetData[j].A,cTab,SheetData[j].B,cTab,SheetData[j].C,cTab,SheetData[j].D,cTab,SheetData[j].E,cTab,SheetData[j].F,cTab,SheetData[j].G,cTab,SheetData[j].H,cTab,SheetData[j].I,cTab,'J',cTab,'K',cTab,'L',cTab,'M',cTab,'N',cTab,'O');
		END;
	Close(fileName);
END;
END;
RUN(Example);

Edited by hippothamus
Link to comment

You'll have to have data in every field. VW read/write functions are not that sophisticated.

Or, you'll have to read each line and count the number of delimiters in a row before valid data and offset your field assignments, (i.e., you'll have to parse the input strings manually.)

Raymond

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...