View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Jim Thomlinson[_3_] Jim Thomlinson[_3_] is offline
external usenet poster
 
Posts: 983
Default Reading dates from text file

I am not following your code. Input reads all the way up to the new line. So
how are you parsing the individual lines? For a CSV file (which is
essentially what you have here) you should look at using the split function.

HTH

"Chris Mahoney" wrote:

Hi

I have a comma-separated text file with several pieces of data in it. I'm
doing this sort of thing to read them in:

Dim ID
Dim DateVar
Dim Name
Dim CodeNo
Open "import.txt" For Input As #1
Do Until EOF(1)
Input #1, ID
Input #1, DateVar
Input #1, Name
Input #1, CodeNo
'Data processing code here
Loop
Close #1

The trouble is that the dates aren't reading in properly. The lines in the
file are in this format:

1,13/03/2004,Chris,4745
2,27/06/2004,Josh,5684
etc.

The problem is that after running the code above, the DateVar variable only
holds the day, not the month (ie. 13 instead of 13/03/2004). If I change Dim
DateVar to Dim DateVar As Date, then I get an Overflow (RTE 6).

Any ideas as to how to get the date reading properly?

Thanks
Chris