MartinS
Active Member
- Joined
- Jun 17, 2003
- Messages
- 487
- Office Version
- 365
- Platform
- Windows
Right, here's the deal.
As part of an application, i have to intereract with another application's data, so therefore I cannot change the layout of this data.
Basically, each month, a new month is added to a 'table' (in a text file) which has 13 delimited columns (a year and 12 months) by, say, for example 10 rows, i.e.
1994,100.1,100.2,100.3,100.4,100.5,100.6,100.7,100.8,100.9,100.0,99.9,99.8
1995,88.1,88.2,88.3,88.4,88.5,88.6,88.7,88.8,88.9,88.0,87.9,87.8
...
...
2003,77.1,77.2,77.3,77.4,77.5,77.6,77.7,77.8,77.9,77.0,76.9,76.8
The idea is the user enters a date into a userform, that date is then passed to my code below and this returns the figure for the year and month, or if not yet available, the latest available figure. The problem I'm having is where the month required is 01/04 but the last available yield is 12/03. It's probably really straightforward to change, but I just can't get my head around what needs to change. So with the above data, if the date "31/01/2004" is passed to the procedure, it would return 76.8 (the latest available figure) (the same would apply for any date in the future), yet if "30/06/2003" was passed, then it would return 77.6.
Here's my code:
If you would like the actual file I'm trying to read then please email me and I will send it to you, but hope my example above should be sufficient.
If I have omitted any required info, please let me know.
Regards, and thanks in advance
Martin
As part of an application, i have to intereract with another application's data, so therefore I cannot change the layout of this data.
Basically, each month, a new month is added to a 'table' (in a text file) which has 13 delimited columns (a year and 12 months) by, say, for example 10 rows, i.e.
1994,100.1,100.2,100.3,100.4,100.5,100.6,100.7,100.8,100.9,100.0,99.9,99.8
1995,88.1,88.2,88.3,88.4,88.5,88.6,88.7,88.8,88.9,88.0,87.9,87.8
...
...
2003,77.1,77.2,77.3,77.4,77.5,77.6,77.7,77.8,77.9,77.0,76.9,76.8
The idea is the user enters a date into a userform, that date is then passed to my code below and this returns the figure for the year and month, or if not yet available, the latest available figure. The problem I'm having is where the month required is 01/04 but the last available yield is 12/03. It's probably really straightforward to change, but I just can't get my head around what needs to change. So with the above data, if the date "31/01/2004" is passed to the procedure, it would return 76.8 (the latest available figure) (the same would apply for any date in the future), yet if "30/06/2003" was passed, then it would return 77.6.
Here's my code:
Code:
Sub ReadNAEIndices(DateToLookFor As String)
NAELogFile="C:\TEMP\AVEARN.DAT"
Dim FileNo As Integer
Dim LastAvailableValue As Double
FileNo = FreeFile()
Open NAELogFile For Input Access Read Shared As #FileNo
Do
On Error Resume Next
For IndCounter = 1 To 12 Step 1
IndValue(IndCounter) = 0
Next IndCounter
Input #FileNo, IndDate, IndValue(1), IndValue(2), _
IndValue(3), IndValue(4), IndValue(5), IndValue(6), _
IndValue(7), IndValue(8), IndValue(9), IndValue(10), _
IndValue(11), IndValue(12)
If EOF(FileNo) Then
For IndCounter = 1 To 12 Step 1
If CDbl(IndValue(IndCounter)) = 0 Then
LastAvailableValue = IndValue(IndCounter - 1)
Exit For
End If
Next IndCounter
If CInt(IndDate) <= Year(DateToLookFor) Then _
IndValue(Month(DateToLookFor)) = LastAvailableValue
Exit Do
End If
On Error GoTo 0
Loop Until CInt(IndDate) = Year(DateToLookFor)
Close #FileNo
End Sub
If I have omitted any required info, please let me know.
Regards, and thanks in advance
Martin