TeamPhotoshop
Reviews, updates and in depth guides to your favourite mobile games - AppGamer.com
Forum Home Latest Posts Search Help Subscribe

Flatfile Filtering

Page: 1 Reply
Dec 30th 2003#135391 Report
Member since: Mar 20th 2001
Posts: 3367
Anyone of you can help me with this program I'm coding. Some basic pseudo code will do cause I'll have to code it in VB.

Basically I have a flatfile and I have to compare each line in the file to see if it is the same as the previous. I've already coded it to sort by the ID want to compare with.

The file now look like so (just show 4 lines)

KKFU 1087960 27122003 1257 NEL
KKFU 1087960 27122003 1926 JP
KKFU 1108451 27122003 1257 NEL
KKFU 1149487 27122003 1257 NEL

The program I've coded can read it line by line. How do I read it 2 lines @ a time(any looping conditions?) and compare the 2?

Currently its :

[php]
Do

Data = wTxtStream.ReadLine 'Read the data

'Get Container number
CntrNum = Mid$(Data, 9, 7)

Loop While (wTxtStream.AtEndOfStream = False)
[/php]

A simple do while loop till the end of the file.. I don't really mind if its in PHP, since I can port it after that. Just need to know the right conditions. Thanks ;)
Reply with Quote Reply
Dec 30th 2003#135404 Report
Member since: Nov 6th 2001
Posts: 240
Do you need the compare the complete line or only a part?

Here's the code to compare a complete line with the previous one.

I've copied a line, so you can see what happens if two values
are equal ....
http://qtone.sidez.net/snippets/sidez/index.php

PHP

[PHP]


sidez



$fh = fopen("file.txt","r");
$data = trim(fread($fh,4096));
$data = explode("\n",$data);

foreach ($data as $key => $val) {
if ($prev_val == $val) {
print "equal
\n";
}
print "curv: $val
prev: $prev_val\n";
print "
\n
\n";

$prev_val = $val;
}
?>


[/PHP]

Visual Basic 6.0
[PHP]
Dim Data(4) As String
Dim CurrentValue As String
Dim PreviousValue As String
Dim Cnt As Integer

Data(0) = "KKFU 1087960 27122003 1257 NEL"
Data(1) = "KKFU 1087960 27122003 1926 JP"
Data(2) = "KKFU 1108451 27122003 1257 NEL"
Data(3) = "KKFU 1108451 27122003 1257 NEL"
Data(4) = "KKFU 1149487 27122003 1257 NEL"

For Cnt = 0 To UBound(Data)
CurrentValue = Data(Cnt)
Debug.Print CurrentValue & " | " & PreviousValue

If StrComp(CurrentValue, PreviousValue) = 0 Then
Debug.Print "equal"
End If

Debug.Print vbCrLf

PreviousValue = CurrentValue
Next Cnt
[/PHP]


Hope this will help you out a bit...
Reply with Quote Reply
Dec 31st 2003#135470 Report
Member since: Mar 20th 2001
Posts: 3367
Cool thanks. I'll work from this. I'm comparing part of the line, the "1087960". If it exists previously in the line, then it will not print in the new flat file. If it's different, then print it. I think the PHP version works better.
Reply with Quote Reply
Jan 2nd 2004#135740 Report
Member since: Mar 20th 2001
Posts: 3367
Thanks QTone .. The PHP version definately helped. Got the program up and running
Reply with Quote Reply
Jan 2nd 2004#135782 Report
Member since: Nov 6th 2001
Posts: 240
no problem sidez, glad I could help you out
Reply with Quote Reply
Page: 1 Back to top
Please login or register above to post in this forum