February 26, 201510 yr G'morning, all: Talk about goofy: one of our users receives a text file on a regular basis where there's no delimiting--it's a fixed string around 4K-long filled with different field data and blank spaces. As I look at it, the data is in block lengths so the first block of data is 50 characters long (including spaces, if any), the second block is 75 characters long (including spaces, if any), etc. So, what I want to do is build a script to import the file into FileMaker (into a global field), then strip the data from the global field into separate text fields. My question is, what's the best practice way of doing that? I was thinking that I'd use a loop to cut the left-most "x" characters from the global field then paste the data into its respective text field and repeat as necessary until there's no data left in the field; it's destructive to the contents of the global field but ithat's no biggie since its contents would be temporary, anyway. However, if I go this route, how would I code the script step to copy just "x" number of characters then delete them? I better put the coffee pot on--this is going to be a long day. :| TIA for your help!
February 26, 201510 yr Instead of looping or other recursion, try Set Field[YourField1; Middle(InputField; 1; 50)] Set Field[YourField2; Middle(InputField; 51; 75)] # etc
February 26, 201510 yr Your description of the incoming format is not clear enough. Does it contain more than one record? If yes, what (if anything) separates the records? In any case, using cut and paste is hardly the optimal solution; just use: Set Field [ TargetTable::Field2 ; Middle ( $chunk ; 51 ; 75 ) ] (as an example for the second block) or perhaps more usefully: Set Field [ TargetTable::Field2 ; Trim ( Middle ( $chunk ; 51 ; 75 ) ) ] where $chunk is a variable containing either the entire imported text or only a part of it representing one record - depending on your answer to my first question.
February 26, 201510 yr +1 comment on the incoming format. if you build something and the incoming format changes by one char it blows up
February 26, 201510 yr if you build something and the incoming format changes by one char it blows up True, but that will happen with any interface you build for importing or exporting: if "they" change their format, it will stop working. In the normal course of things, these formats are not supposed to change, precisely for this reason (and if anyone is still using a fixed-length format, they're not very likely to change it now anyway).
February 26, 201510 yr Author Sorry, I forgot to include that--a carriage return separates each record. I sanitized the file and it has two records--it's attached. (The character count differs because I didn't match block lengths when substituting data, but you get the idea.) Sample.txt
February 27, 201510 yr a carriage return separates each record. In such case I'd suggest you do it along these lines: Set Variable [ $allRecords; SourceTable::gText ] Go to Layout [ TargetTable] Loop Set Variable [ $i; $i + 1 ] Exit Loop If [ $i > ValueCount ( $allRecords) ] Set Variable [ $record; GetValue ( $allRecords ; $i ) ] New Record/Request Set Field [ TargetTable::Field1; Trim ( Middle ( $record ; 1 ; 50 ) ) ] Set Field [ TargetTable::Field2; Trim ( Middle ( $record ; 51 ; 75 ) ) ] # ... set more fields ... End Loop Commit Records/Requests
Create an account or sign in to comment