-
I am working with a text file in which the data needs to be manipulated and written to a new file. Each record in the first text file begins with either an I an O a C or a N. All the I records go into one text file, all the O,C, and N's go into another text file. I wrote the code using the open file for input command and inputed to records fields into variables. I have to do this because the data needs to be moved around when inputed into the new text files. The problem is, that the records beginning with C, and N do not contain on of the fields that all the other records do, so I can't get it to read the entire file because it comes up with an error. Any suggestions?????
-
Hi Rachael?,
I think your problem lies in the fact that you are opening the file for INPUT when you should be opening for INPUT OUTPUT as when opened for INPUT you can only Input from the file not Output to it.
I hope this helps if not you could always email me
DocZaf
{;->
-
Well actually I know I opened the file right because the file I input from is raw data and the file I write to is completely different. The problem lies in the Read statement, because I know that you have to have the same number of variables as you do the fields in the raw data file. I just wanted to know if there is another way to input the file into variables if there isn't the same number of fields as the variables. Most of the raw data file has the number of fields to match the variables I created, it's just that some of them records are missing one field.
-
Hi Rach,
If all of the records you are loading and saving always contain the same length fields then maybe you should be using Random access instead, see below:
In Declarations Section
Type MyRecordInfo
'im prefixing with mr to show me its my record info
mrIndex as Integer
mrName as String * 30
mrStreet as String * 30
mrDistrict as String * 30
mrCity as string * 30
mrTelephone as string *15
End Type
Public TmpRecord as MyRecordInfo
Public MyRecord as MyRecordInfo
The Actual Routine to load/save
Sub SomethingOrOther(tThisRecordIndexNumber as Integer)
Open MyFile for Random as #1 Len = Len(TmpRecord)
'or
Open MyFile for Random as #1 Len = Len (137)
'as this is the length of each and every record
'use this to read an individual record
Get #1, tThisRecordIndexNumber,MyRecord
'use this to read all records
counta =1
Do
Get #1,counta,MyRecord
'process your data here
'save it like this
Put #1,counta,MyRecord
Loop until Eof(1)
Close #1
End Sub
Alternatively you could use arrays instead and REDIMemsion them at run time.
If your still stuck email me, I have to jet now as duty calls, I hope the info above helps you anyway.
DocZaf
{;->