Hippocode Posted June 24, 2013 Share Posted June 24, 2013 (edited) 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 June 24, 2013 by hippothamus Quote Link to comment
MullinRJ Posted June 25, 2013 Share Posted June 25, 2013 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 Quote Link to comment
Hippocode Posted June 25, 2013 Author Share Posted June 25, 2013 I went the manual way, with a looping function to explode the full string it's not so bad at all. Quote Link to comment
Pat Stanford Posted June 25, 2013 Share Posted June 25, 2013 Make sure you check out the difference between the Read and StdRead procedures. StdRead was added to make it easier to bring in the entire line of data to parse. Quote Link to comment
Recommended Posts
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.