Jump to content

Comma deliminator data format


John Gr

Recommended Posts

H there

i am in the process of creating a script that would access an external data file.

The data file uses a comma deliminator format.

I would like to READ this data into VW script.

As far i can see VW only uses a TAB deliminator.

Any ideas...

cheers

John Greaney

Win Vista

2008

Link to comment

I think you will have to write your own parsing routine.

Use StdRead or StdReadLn to get the data into a variable and then run through it looking for commas.

Sam Jones and John McKernon are probably the leading experts in getting data into and out of VW. Maybe one of them will chime in.

If you need help with the parsing, just ask and I am sure we can come up with a solution.

How much data do you need to bring in? If it is only a few items, then speed does not really matter. If it is thousands of lines, speed will be of more concern.

Link to comment

Hi John,

I do this a lot. Here is a sample script. You'll have to add a loop and a READLN() to import multiple records.

HTH,

Raymond

PROCEDURE ParseIt;
{ Copyright 2010 Raymond J. Mullin }
CONST
  Comma = ',';
VAR
  S, T :String;
  param1 : Integer;
  param2 : Real;
  param3 : String;
  param4 : Boolean;


  function GetParam (var S :String; Delim :Char) :String;
  { Return the first substring of S up to the Delim character, }
  { and delete the substring from S. }
  Var
     DelimPos : Integer;
  Begin
     DelimPos := pos(Delim, S);
     if (DelimPos > 0) then
        GetParam := copy(S, 1, DelimPos-1);
        delete(S, 1, DelimPos);
     end
     else GetParam := '';
  End;   { GetParam  }


  function UpperStr (S :String) :String;
  { Return UPPER CASE of String S. }
  Begin
     UprString(S);
     UpperStr := S;
  End;   { UpperStr }


BEGIN
  S := concat(7, Comma, 15.2, Comma, 'Texty Stuff', Comma, 'True');	  { test string }
  T := S;   { a copy of S }

  S := concat(S, Comma);   { add a delimeter to the end of S if one is not already there }
  param1 := Str2Num(GetParam(S, Comma));
  param2 := Str2Num(GetParam(S, Comma));
  param3 := GetParam(S, Comma);
  param4 := UpperStr(GetParam(S, Comma)) = 'TRUE';


  message(T, '   --->   ', param1, '    ', param2, '    ', param3, '    ', param4);
END;
Run(ParseIt);

Link to comment

Hi there Guys

Thanks for your replies.

I will try the code you have posted.

I have added the file that contains the data i require.

The data is at the end of the file. the last 2 lines.

The data contains fixing details for a particular truss. GT1.

Thanks Again

John Greaney

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...