Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Extracting field from a record in a text file

Status
Not open for further replies.

chillydog

Technical User
Jan 17, 2001
2
US
I have a problem in extracting field in a record which is text delimited in a file, i need to extract oly few fields which are in specific columns and rows within a record and a records has specific length, So guys whoever have an idea please help, need really bad
 
That isn't so hard if you know the record structure. Here's an example that opens a file with a known structure and searches for an employee named Albert Einstein. It then reports the department he works in and his home phone number.
[tt]
' $DYNAMIC
DEFINT A-Z
TYPE RecordStructure
EmployeeNumber AS STRING * 5
EmployeeName AS STRING * 32
HourlyRate AS LONG
Department AS STRING * 12
HomePhone AS STRING * 14
END TYPE
REDIM Record(1) AS RecordStructure
Search$ = "Albert Einstein"
ff = FREEFILE
OPEN "C:\EmpTable.bin" FOR BINARY AS #ff
NumRecs = LOF(ff) / LEN(Record(1))
Found = 0
FOR Rec = 1 TO NumRecs
GET #ff, , Record(1)
IF RTRIM$(Record(1).EmployeeName) = Search$ THEN
Found = 1
EXIT FOR
END IF
NEXT
CLOSE #ff
IF Found = 1 THEN
EmpDat$ = Search$ + " works in "
EmpDat$ = EmpDat$ + RTRIM$(Record(1).Department)
EmpDat$ = EmpDat$ + " and his home phone number is "
EmpDat$ = EmpDat$ + RTRIM$(Record(1).HomePhone)
PRINT EmpDat$
ELSE
PRINT Search$; " is not listed in the database."
END IF
[/tt]

"Technological progress is like an ax in the hands of a pathological criminal"
Albert Einstein
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top