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

Database/Text File string compare problems.

Status
Not open for further replies.

LucyFur

IS-IT--Management
Jul 8, 2002
3
US
I am having a problem with using the "strComp" function in vbscript. I have two string sources that I am trying to compare and they are never equal when being compared even though I response.write both strings and they are identical. One string is coming from an access 2000 database and they other string is being taken from a .txt file using regex and pattern matching it. I am opening the .txt file as text and I tried using vbTextCompare and vbBinaryCompare with the strComp function and they both dont work. Does anyone have any ideas as to what I might be missing? Thanks in advance.

Lucy Fur
 
Perhaps post your code as well so we can see the syntax. Are the fields both text or is the access table field numeric? Have you tried lcase(string1) = lcase(string2)? Just a thought.
 
I know that this code is messy and can probably be done about 1 million times more easily. =( But please bear in mind that I am a noob coder and I am trying my best. =( Thank you very much for all your help, I appreciate it. Also, if you go to you can see the code in action. On the right side of the page if you scroll down about 2 pages you will see a player named 'Fasin Kivna'. You will see 'Fasin Kivna Fasin Kivna' 'I guess they DONT match'. One Name is from the text file and the other is from the database, but they are not matching. Here is the code:
<!-- EternX Rankings Area Start-->
<%

Dim adoCon 'Database Connection Variable
Dim rsTemp 'Holds the configuartion recordset
Dim strCon 'Holds the Database driver and the path and name of the database
Dim strSQL 'Holds the SQL query for the database

'Create a connection object
Set adoCon = Server.CreateObject(&quot;ADODB.Connection&quot;)

'Database connection info and driver
strCon = &quot;DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=&quot; & Server.MapPath(&quot;nwnrankings.mdb&quot;)
'strCon = &quot;Provider=Microsoft.Jet.OLEDB.4.0; Data Source=&quot; & Server.MapPath(&quot;nwnrankings.mdb&quot;)

'Set an active connection to the Connection object
adoCon.Open strCon, , adLockOptimistic, adCmdTable

'Read in the configuration for the script
'Intialise the ADO recordset object
Set rsTemp = Server.CreateObject(&quot;ADODB.Recordset&quot;)

'Initialise the SQL variable with an SQL statement to get the configuration details from the database
strSQL = &quot;SELECT tblNWNRank.* From tblNWNRank;&quot;

'Query the database
rsTemp.Open strSQL, strCon, , adLockOptimistic, adCmdText

Function regexTest(expression, text)
dim regEx
Set regEx = New RegExp
regEx.Pattern = expression
regEx.IgnoreCase = True
regEx.Global = True
set dateMatch = regEx.Execute(text)
If dateMatch.Count > 0 Then
regexTest = dateMatch.Item(0).Value
End If
set regEx = Nothing
End Function

dim objFile, strTextFile, strGetName, objFileTS, objFSO, strLogFileName, dateMatch, i, intEndMatches, x, j, duplicate, intCompareNames
dim DeadPlayers()
set objFSO = CreateObject(&quot;scripting.FileSystemObject&quot;)
strLogFileName = &quot;c:\Inetpub\eternxroot\nwserverLog1.txt&quot;

if objFSO.FileExists(strLogFileName) then
set objFile = objFSO.GetFile(strLogFileName)
Const ForReading = 1
Const TriStateFalse = 0
set objFileTS = objFile.OpenAsTextStream(ForReading,TriStateFalse)
strTextFile = objFileTS.ReadAll
strGetName = regexTest(&quot;<D>\w+\s\w+<D>&quot;,strTextFile)

i = 0
intEndMatches = dateMatch.Count -1
Redim DeadPlayers(intEndMatches)
For j = 0 To intEndMatches
DeadPlayers(j) = trim(dateMatch.Item(j).Value)
Next

for each x in DeadPlayers
Do While Not (rsTemp.EOF)

Response.Write i & &quot;<BR>&quot;
Response.Write DeadPlayers(i) & &quot; &quot; & rsTemp(&quot;PlayerName&quot;) & &quot;<BR>&quot;

intCompareNames = StrComp(rsTemp(&quot;PlayerName&quot;), DeadPlayers(i), 0)
Response.Write &quot;Compare Names Output&quot; & intCompareNames & &quot;<BR>&quot;
if intCompareNames = 0 Then
'If (StrComp(rsTemp(&quot;PlayerName&quot;), DeadPlayers(i), 0) = 0) Then
'If rsTemp(&quot;PlayerName&quot;) <> DeadPlayers(i) Then
Response.Write &quot;I guess they MATCH&quot; & &quot;<BR>&quot;
else
Response.Write &quot;I guess they DONT match&quot; & &quot;<BR>&quot;
rsTemp.MoveNext
end if

Loop
i = i + 1
rsTemp.MoveFirst
next

else
end if

rsTemp.Close
%>
 
As JohnYingling pointed out, you probably need to trim your strings.
Also, you're performing a binary comparison, so case must match extactly as well. Jon Hawkins
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top