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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Record Accessing problem?

Status
Not open for further replies.

Cap2010

Programmer
Mar 29, 2000
196
CA
Below is my code for the flow to check a flat file. and read every line.

Question is it skips one record i.e. tablenumber2 and want to add the records
for tablenumber2.



Following are the criteria to check and process.
1) check for the table number
2) on finding the table number
check
2.1) anywhere the word starting with PR1 and in that line to check
whether there is a word called ADD or LESS (if it is there store value)
(ADD or LESS can come any in the flat file)

2.2) if the criteria for the above 2.1 is met i.e. found PR1 and does not
have ADD or LESS and has a summary than do the process and store value.

all these are to be done in a loop for each table number and to check when the
table number changes.


e.g. for a flat file

------------------------
Date description qty
------------------------
TableNumber1
22-6-02 item1 3
PR1 ljflsdjf ADD 5
22-6-02 item3 0

PR1 Summary
Total Item 1 Added
Total Item 1 Deducted

------------------------------ (this line may be present at times)

TableNumber2
22-6-02 item4 2
22-6-02 item5 1
PR1 ljflsdjf ADD 4

PR1 Summary
Total Item 2 Added 5
Total Item 2 Deducted 6
PR1 ljflsdjf ADD 5


PR1 kjlfsadflkj LESS 4
-------------------------------------------------------------
TableNumber3

22-6-02 item4 2
22-6-02 item5 1

PR1 Summary
Total Item 2 Added 5
Total Item 2 Deducted 6
--------------------------------------

The code is as follows :

Do While Not EOF(varFileNumber)

Line Input #varFileNumber, varLineString

varTableNumber = Left(varLineString, 11)

If varTableNumber = "TableNumber" Then

pTerminalId = Right(varLineString, 1)
vCheckTerminalId = pTerminalId

Line Input #varFileNumber, varLineString

Do While varPR1 <> &quot;PR1&quot;
Line Input #varFileNumber, varLineString
varPR1 = Mid(varLineString, 2, 4)
Loop


If varPR1 = &quot;PR1&quot; Then
varADDLESS = Mid(varLineString, 45, 4)

If varADDLESS = &quot;ADD&quot; Or varADDLESS = &quot;LESS&quot; Then
Line Input #varFileNumber, varLineString
varPR1 = &quot;&quot;
End If

End If

varPR2 = varPR1


Do While varPR2 = &quot;PR1&quot;
'Processing to store records
Loop 'PR1

Loop

End If

Loop ' EOF of Raw File

Regards

 
Its usually better when processing text files sequentially to stick to a single line for reading the file, then have your loop code determine how to handle that line. For example:

Do While Not EOF(varFileNumber)
Line Input #varFileNumber, varLineString
If Left(varLineString, 11) = &quot;TableNumber&quot; Then
pTerminalId = Right(varLineString, 1)
vCheckTerminalId = pTerminalId
ElseIf Mid(varLineString, 2, 4) = &quot;PR1&quot; Then
if Mid(varLineString, 45, 4) = &quot;ADD &quot; Or _
Mid(varLineString, 45, 4) = &quot;LESS&quot; Then
<code to process PR1 Line>
EndIf 'ingnore other lines with &quot;PR1&quot; in them
ElseIf Isnumber(Left(varLineString,1)) Then
<code to process Item line>
endif 'ignore any other lines
Loop

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top