 |
| ASP Forms As of Oct 5, 2005, this forum is now locked. Please use "Classic ASP beginner" at http://p2p.wrox.com/forum.asp?FORUM_ID=54 or "Classic ASP Professional" http://p2p.wrox.com/forum.asp?FORUM_ID=56 instead. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the ASP Forms section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

November 23rd, 2004, 11:39 PM
|
|
Authorized User
|
|
Join Date: Oct 2004
Posts: 32
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Compare Data in two txt file
Hi Everybidy,
my supervisor is asking me to do a comparation data in two diffrent txt file.
thats mean,
if data(textfile1) <> data(textfile2) then print.....
the data format is as below:
"FileName","NoOfPages","Date(YMD)","user"
please help me.....(hehe)
thank you
bey
|
|

November 24th, 2004, 01:59 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
|
|
Hi Bey,
Use filesystemobject (FSO) and read both the files in to two different objects. Use READLINE() function to read line from both the files into its own string variables. Use SPLIT() function to split the line in to array, having COMMA as delimiter. Then from LBOUND() to UBOUND() of the array run a for loop. and compare the subscript value of array1 with that of array2. If you wanted case-insensitive result, better convert both the array values in to single case before comparision. Use LCASE() / UCASE() function to do so.
Try this at your end. If you find difficulties with your code post here, we will take a look.
Hope that helps.
Cheers!
_________________________
- Vijay G
Strive for Perfection
|
|

November 24th, 2004, 10:26 PM
|
|
Authorized User
|
|
Join Date: Oct 2004
Posts: 32
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
this is my code...
but still have problem...
now i can retieve the data from both text file...
but i have no idea how to using the do until & loop to compare the data from both text file...
please help me.... :(
bey
<%
Option Explicit
'Code to display data from the current text-based logfile
Dim objFSO, oInStream, sLine, sSeg
Dim objFSO1, oInStream1, sLine1, sSeg1
'Define the constants used by the FSO
Const Forreading = 1
'Create an instance of the FSO
Set objFSO = CreateObject("Scripting.fileSystemObject")
Set objFSO1 = CreateObject("Scripting.fileSystemObject")
'Check the file exists
If objFSO.fileExists( Server.MapPath( "20041124.txt" ) ) Then
'Open a file for reading
Set oInStream = objFSO.OpenTextfile( Server.MapPath( "20041124.txt" ), Forreading, False )
Do Until oInStream.AtEndOfStream
sLine = oInStream.ReadLine
sSeg = Split( sLine, "," )
session("filename") = sSeg(0)
session("NoOfPages") = sSeg(1)
session("date") = sSeg(2)
session("user") = sSeg(3)
session("check") = session("filename") + session("NoOfPages") + session("date") + session("user")
Set oInStream1 = objFSO1.OpenTextfile( Server.MapPath( "20041125.txt" ), Forreading, False )
while session("check") <> session("check1")
sLine1 = oInStream1.ReadLine
sSeg1 = Split( sLine1, "," )
session("filename1") = sSeg1(0)
session("NoOfPages1") = sSeg1(1)
session("date1") = sSeg1(2)
session("user1") = sSeg1(3)
session("check1") = session("filename1") + session("NoOfPages1") + session("date1") + session("user1")
response. write session("check1")
response. write "<br>"
wend
Loop
oInStream.Close
Set oInStream = Nothing
Else
Response.Write "file not found!"
End If
Set objFSO = Nothing
%>
|
|

November 25th, 2004, 02:43 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
|
|
Try this.
Code:
Option Explicit
'Code to display data from the current text-based logfile
Dim objFSO, oInStream, sLine, sSeg
Dim objFSO1, oInStream1, sLine1, sSeg1
dim flagCompare
flagCompare = true
'Define the constants used by the FSO
Const Forreading = 1
'Create an instance of the FSO
Set objFSO = CreateObject("Scripting.fileSystemObject")
Set objFSO1 = CreateObject("Scripting.fileSystemObject")
'Check the file exists
If objFSO.fileExists( Server.MapPath( "20041124.txt" ) ) Then
'Open a file for reading
Set oInStream = objFSO.OpenTextfile( Server.MapPath( "20041124.txt" ), Forreading, False )
If objFSO1.fileExists( Server.MapPath( "20041125.txt" ) ) Then
Set oInStream1 = objFSO1.OpenTextfile( Server.MapPath( "20041125.txt" ), Forreading, False )
Do
sLine = oInStream.ReadLine
sLine1 = oInStream1.ReadLine
If len(trim(SLine))>0 and len(trim(SLine1))>0 then
sSeg = Split( sLine, ",")
sSeg1 = Split( sLine1, ",")
'I dont see any need for session to be used here.
for i=0 to ubound(sSeg)
If (strComp(LCASE(sSeg(i)), LCASE(sSeg1(i))) <> 0) then
flagCompare = false
Exit For
End If
Next
End If
If flagCompare = false then exit Do
Loop While NOT oInStream.AtEndOfStream and NOT oInStream1.AtEndOfStream
If flagCompare = false then
Response.write "Files are NOT similar"
Else
Response.write "Files are similar"
End If
'I dont see any need for the following line, as you wanted to compare two files.
session("check") = session("filename") + session("NoOfPages") + session("date") + session("user")
Else
Response.Write "file2 not found!"
End If
Else
Response.Write "file1 not found!"
End If
oInStream.Close
oInStream1.Close
Set oInStream = Nothing
Set oInStream1 = Nothing
Set objFSO = Nothing
Set objFSO1 = Nothing
Hope that helps.
Cheers!
_________________________
- Vijay G
Strive for Perfection
|
|
 |