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

string comparison problems 1

Status
Not open for further replies.

edpatterson

IS-IT--Management
Feb 24, 2005
186
I am trying to determine if a file has been modified since a script last ran. The last modification date information is stored in a text file. When the script runs it reads the file and checks that value against a objFile.DateLastModified call. The last modified date in the file is identical to the one returned yet the comparison fails.

Code:
Option Explicit

Dim strFilein, strLinein, strTestTime
Dim dicFileData
Dim intCount
Dim objFSO, objTSO, objFile 
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTSO = objFSO.CreateTextFile("test.txt")
objTSO.Close
Set objTSO = objFSO.CreateTextFile("test2.txt")
Set objFile = objFSO.GetFile("test.txt")
strTestTime = cdate(objFile.DateLastModified)
objTSO.WriteLine strTestTime
objTSO.Close
Set objTSO = objFSO.OpenTextFile("test2.txt")
strLinein = Trim(objTSO.ReadLine)

' In theory strLinein = objFile.DateLastModified
If strLinein <> CDate(objFile.DateLastModified) Then
	WScript.Echo "They are different"
	WScript.Echo strLinein&"."
	WScript.Echo CDate(objFile.DateLastModified)&"."
Else
	WScript.Echo "They are the same"
End If
Even though the values are identical (as far as I can see) the <> tests positive.

Perhaps I have simply looked at it too long.

Ed
 
What if you changed it to:

CDate(strLinein) <> CDate(objFile.DateLastModified)

--------------------------------------------------------------------------------
dm4ever
My philosophy: K.I.S.S - Keep It Simple Stupid
 
Thanks a million! It works but I am rather confused. The output to screen and file appeared to be identical so why did the comparison fail? I would not thing that any conversion took place during the writeline or readline calls.

Ed
 
data type is the difference. one becomes date (CDate), the other one is a string.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top