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

Type Mismatch Error: CDate

Status
Not open for further replies.

jessiejane

Programmer
Oct 29, 2009
32
US
I am getting an error: Type mismatch CDate

I have a text file and when the records in the text files complete 60 days then it writes to a file else puts in a seperate array. I get type mismatch error at CDate.

I am not knowing where its going wrong. Any help is appreciated.

The text file in format:
JOHN-03/04/2010
MARY-07/10/2010

------------------
Code
-------------------
strData = objFSO.OpenTextFile(strDirectory & strFile, strReadingValue).ReadAll
arrLines = Split(strData,vbCrLf)
i=0
For Each strLine in arrLines
Dim x
x = len(strLine)
strDate = Mid(strLine,instr(strLine, "-")+1)
PDate = Cdate(strDate)
todayDate = Date
NumOfDays = DateDiff("d", PDate, todayDate)
if NumOfDays >=60 then

objText.WriteLine(strLine)
Else
Redim Preserve arrInterArray(lineNumber)
arrInterArray(i) = strLine
i=i+1
End If

Next
 


Hi,

It is not clear from your post
[tt]
JOHN-03/04/2010
MARY-07/10/2010
[/tt]
Is the structure of your date in the string...
[tt]
mm/dd/yyyy
dd/mm/yyyy
[/tt]
????

My guess is that whatever regional date settings, the CDATE() function expects the string to have the OTHER structure and a value, 13 or more, shows up in what it expects to be the MONTH, and ....
[red]
TILT![/red]



Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 


BTW, in case you did not know, Bill Gates lives in the state of Washington in the USA.

My suggestion: Always, whenever possible, use the UNAMBIGUOUS yyyy/mm/dd structure.

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
The format is in mm/dd/yyy. Not sure of how to get rid of the error.
 



What is the exact "date" string at the time of the error?

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top