I have another issue with somedates are missing.
code in vba
when i click the button it reads from the open text file name QrtlyRateDel.txt and writes QrtlyRateExludeMEdate.txt
this is the sample text file for qrtlyRateDel
ABCD,RUP,MKNT,08/29/08 0.21200000
ABCD,RUP,MKNT,08/28/08 0.20610000
ABCD,RUP,MKNT,08/27/08 0.19840000
ABCD,RUP,MKNT,08/26/08 0.19680000
ABCD,RUP,MKNT,08/25/08 0.20740000
ABCD,RUP,MKNT,08/22/08 0.20850000
ABCD,RUP,MKNT,08/21/08 0.21810000
ABCD,RUP,MKNT,08/20/08 0.22670000
ABCD,RUP,MKNT,08/19/08 0.22520000
ABCD,RUP,MKNT,08/18/08 0.22340000
ABCD,RUP,MKNT,08/15/08 0.21650000
ABCD,RUP,MKNT,08/14/08 0.22590000
when it writes from the above sample
it is missing the dates 08/15/08 and 08/22/08
ABCD,RUP,MKNT,08/29/08 0.21200000
ABCD,RUP,MKNT,08/28/08 0.20610000
ABCD,RUP,MKNT,08/27/08 0.19840000
ABCD,RUP,MKNT,08/26/08 0.19680000
ABCD,RUP,MKNT,08/25/08 0.20740000
ABCD,RUP,MKNT,08/21/08 0.21810000
ABCD,RUP,MKNT,08/20/08 0.22670000
ABCD,RUP,MKNT,08/19/08 0.22520000
ABCD,RUP,MKNT,08/18/08 0.22340000
ABCD,RUP,MKNT,08/14/08 0.22590000
this is the code i am using for the above
Private Sub cmdScanRemoveRates_Click()
Dim ReadRates
Dim strEffDate, strYear, strDayName
Dim Default, strNextdayName, strNextDATE As String
Dim intDayNum, IntSum
Dim SourceFile, DestinationFile
Dim OriginalQRDfile As String
Dim LastDateRemoved As String
Dim MakeOriginal As String
Dim OriginYear As Integer
Dim OriginMonth As Integer
OriginalQRDfile = "C:\QrtlyRateDel.txt"
LastDateRemoved = "C:\QrtlyRateExludeMEdate.txt" 'QrtlyRateDel.txt"
Open OriginalQRDfile For Input As #1
Open LastDateRemoved For Output As #2
Open Backup For Output As #3
Do While Not EOF(1)
READNEXTREC: Line Input #1, ReadRates ' Read line into variable.
On Error Resume Next
If ReadRates = "" Then
GoTo READNEXTREC
Else
LenReadRates = Len(ReadRates)
If LenReadRates = 8 Or LenReadRates = 10 Then
RevalPriorToDate = ReadRates
GoTo READNEXTREC
End If
If ReadRates = "99999" Then
Print #2, ReadRates
Print #3, ReadRates
MsgBox "Scan And Remove Completed.", vbInformation
Exit Do
Else
strEffDate = Mid(ReadRates, 16, 8)
OriginYear = Mid(strEffDate, 7, 3)
strEffDate = Format(strEffDate, "dd-mmm-yyyy")
OriginMonth = Month(strEffDate)
LastDay OriginYear, OriginMonth, strEffDate, ReadRates, RevalPriorToDate
End If
End If
Loop
ExcludeFile = LastDateRemoved
Close #1
Close #2
Close #3
End Sub
Public Function LastDay(intOriginYear As Integer, intOriginMonth As Integer, ByVal strEffDate As Date, ByVal InputReadRates, ByVal RevalPriorToDate) As Variant
' **************************************************************************
' * Checks to see if the date from the file is the last day of the month. *
' * Prints if the day is NOT the last day of the month. *
' ***************************************************************************
Dim intCheck, intDayName, strDiff
Dim strDate, strCheckDate As Date
LastDay = Day(DateSerial(intOriginYear, intOriginMonth + 1, 0))
strDate = Day(strEffDate)
strCheckDate = intOriginMonth & "/" & LastDay & "/0" & intOriginYear
strDiff = DateDiff("d", strEffDate, strCheckDate, vbUseSystemDayOfWeek)
intDayName = Weekday(Format(strEffDate, "mmm dd, yyyy"))
strCurrentDay = Format(strEffDate, "dddd")
strNextDay = Format(strCheckDate - 1, "dddd")
strAfterNextday = Format(strCheckDate, "dddd")
strGeneralDate = Mid(strEffDate, 1, 5)
If strDate = LastDay Then
Else
If strDiff <= 3 And strNextDay = "Saturday" Or strNextDay = "Saturday" Then
'If strDiff <= 2 And strNextDay = "Saturday" Or strNextDay = "Saturday" Then
If intDayName = 1 Or intDayName = 7 Then 'Sun or Sat
Else
strNumEffDate = Format(strEffDate, "General Number")
strNow = Format(Now, "mm/dd/yy")
strNowMonth = Format(Now, "mm")
strNowConstantDay = "01"
strNowYear = Format(Now, "yyyy")
strNumber = strNowMonth & "/" & strNowConstantDay & "/" & strNowYear
strStaticRevalPriorToDate = Format(RevalPriorToDate, "General Number") '
If strCurrentDay = "Friday" And strNextDay = "Saturday" And strAfterNextday = "Sunday" Then
ElseIf strCurrentDay = "Friday" And strNextDay = "Friday" And strAfterNextday = "Saturday" Then
Else
If strNumEffDate < strStaticRevalPriorToDate Then
Print #2, InputReadRates
End If
End If
End If
Else
If intDayName = 1 Or intDayName = 7 Then 'Sun or Sat
Else
strNumEffDate = Format(strEffDate, "General Number")
strNow = Format(Now, "mm/dd/yy")
strNowMonth = Format(Now, "mm")
strNowConstantDay = "01"
strNowYear = Format(Now, "yyyy")
strFullDate = strNowMonth & "/" & strNowConstantDay & "/" & strNowYear
strStaticRevalPriorToDate = Format(RevalPriorToDate, "General Number") '
If strCurrentDay = "Friday" And strNextDay = "Saturday" And strAfterNextday = "Sunday" Then
'ElseIf strCurrentDay = "Friday" And strAfterNextday = "Saturday" Then
ElseIf strCurrentDay = "Friday" And strNextDay = "Friday" And strAfterNextday = "Saturday" Then
Else
If strNumEffDate < strStaticRevalPriorToDate Then
Print #2, InputReadRates
End If
End If
End If
End If
End If
End Function
code in vba
when i click the button it reads from the open text file name QrtlyRateDel.txt and writes QrtlyRateExludeMEdate.txt
this is the sample text file for qrtlyRateDel
ABCD,RUP,MKNT,08/29/08 0.21200000
ABCD,RUP,MKNT,08/28/08 0.20610000
ABCD,RUP,MKNT,08/27/08 0.19840000
ABCD,RUP,MKNT,08/26/08 0.19680000
ABCD,RUP,MKNT,08/25/08 0.20740000
ABCD,RUP,MKNT,08/22/08 0.20850000
ABCD,RUP,MKNT,08/21/08 0.21810000
ABCD,RUP,MKNT,08/20/08 0.22670000
ABCD,RUP,MKNT,08/19/08 0.22520000
ABCD,RUP,MKNT,08/18/08 0.22340000
ABCD,RUP,MKNT,08/15/08 0.21650000
ABCD,RUP,MKNT,08/14/08 0.22590000
when it writes from the above sample
it is missing the dates 08/15/08 and 08/22/08
ABCD,RUP,MKNT,08/29/08 0.21200000
ABCD,RUP,MKNT,08/28/08 0.20610000
ABCD,RUP,MKNT,08/27/08 0.19840000
ABCD,RUP,MKNT,08/26/08 0.19680000
ABCD,RUP,MKNT,08/25/08 0.20740000
ABCD,RUP,MKNT,08/21/08 0.21810000
ABCD,RUP,MKNT,08/20/08 0.22670000
ABCD,RUP,MKNT,08/19/08 0.22520000
ABCD,RUP,MKNT,08/18/08 0.22340000
ABCD,RUP,MKNT,08/14/08 0.22590000
this is the code i am using for the above
Private Sub cmdScanRemoveRates_Click()
Dim ReadRates
Dim strEffDate, strYear, strDayName
Dim Default, strNextdayName, strNextDATE As String
Dim intDayNum, IntSum
Dim SourceFile, DestinationFile
Dim OriginalQRDfile As String
Dim LastDateRemoved As String
Dim MakeOriginal As String
Dim OriginYear As Integer
Dim OriginMonth As Integer
OriginalQRDfile = "C:\QrtlyRateDel.txt"
LastDateRemoved = "C:\QrtlyRateExludeMEdate.txt" 'QrtlyRateDel.txt"
Open OriginalQRDfile For Input As #1
Open LastDateRemoved For Output As #2
Open Backup For Output As #3
Do While Not EOF(1)
READNEXTREC: Line Input #1, ReadRates ' Read line into variable.
On Error Resume Next
If ReadRates = "" Then
GoTo READNEXTREC
Else
LenReadRates = Len(ReadRates)
If LenReadRates = 8 Or LenReadRates = 10 Then
RevalPriorToDate = ReadRates
GoTo READNEXTREC
End If
If ReadRates = "99999" Then
Print #2, ReadRates
Print #3, ReadRates
MsgBox "Scan And Remove Completed.", vbInformation
Exit Do
Else
strEffDate = Mid(ReadRates, 16, 8)
OriginYear = Mid(strEffDate, 7, 3)
strEffDate = Format(strEffDate, "dd-mmm-yyyy")
OriginMonth = Month(strEffDate)
LastDay OriginYear, OriginMonth, strEffDate, ReadRates, RevalPriorToDate
End If
End If
Loop
ExcludeFile = LastDateRemoved
Close #1
Close #2
Close #3
End Sub
Public Function LastDay(intOriginYear As Integer, intOriginMonth As Integer, ByVal strEffDate As Date, ByVal InputReadRates, ByVal RevalPriorToDate) As Variant
' **************************************************************************
' * Checks to see if the date from the file is the last day of the month. *
' * Prints if the day is NOT the last day of the month. *
' ***************************************************************************
Dim intCheck, intDayName, strDiff
Dim strDate, strCheckDate As Date
LastDay = Day(DateSerial(intOriginYear, intOriginMonth + 1, 0))
strDate = Day(strEffDate)
strCheckDate = intOriginMonth & "/" & LastDay & "/0" & intOriginYear
strDiff = DateDiff("d", strEffDate, strCheckDate, vbUseSystemDayOfWeek)
intDayName = Weekday(Format(strEffDate, "mmm dd, yyyy"))
strCurrentDay = Format(strEffDate, "dddd")
strNextDay = Format(strCheckDate - 1, "dddd")
strAfterNextday = Format(strCheckDate, "dddd")
strGeneralDate = Mid(strEffDate, 1, 5)
If strDate = LastDay Then
Else
If strDiff <= 3 And strNextDay = "Saturday" Or strNextDay = "Saturday" Then
'If strDiff <= 2 And strNextDay = "Saturday" Or strNextDay = "Saturday" Then
If intDayName = 1 Or intDayName = 7 Then 'Sun or Sat
Else
strNumEffDate = Format(strEffDate, "General Number")
strNow = Format(Now, "mm/dd/yy")
strNowMonth = Format(Now, "mm")
strNowConstantDay = "01"
strNowYear = Format(Now, "yyyy")
strNumber = strNowMonth & "/" & strNowConstantDay & "/" & strNowYear
strStaticRevalPriorToDate = Format(RevalPriorToDate, "General Number") '
If strCurrentDay = "Friday" And strNextDay = "Saturday" And strAfterNextday = "Sunday" Then
ElseIf strCurrentDay = "Friday" And strNextDay = "Friday" And strAfterNextday = "Saturday" Then
Else
If strNumEffDate < strStaticRevalPriorToDate Then
Print #2, InputReadRates
End If
End If
End If
Else
If intDayName = 1 Or intDayName = 7 Then 'Sun or Sat
Else
strNumEffDate = Format(strEffDate, "General Number")
strNow = Format(Now, "mm/dd/yy")
strNowMonth = Format(Now, "mm")
strNowConstantDay = "01"
strNowYear = Format(Now, "yyyy")
strFullDate = strNowMonth & "/" & strNowConstantDay & "/" & strNowYear
strStaticRevalPriorToDate = Format(RevalPriorToDate, "General Number") '
If strCurrentDay = "Friday" And strNextDay = "Saturday" And strAfterNextday = "Sunday" Then
'ElseIf strCurrentDay = "Friday" And strAfterNextday = "Saturday" Then
ElseIf strCurrentDay = "Friday" And strNextDay = "Friday" And strAfterNextday = "Saturday" Then
Else
If strNumEffDate < strStaticRevalPriorToDate Then
Print #2, InputReadRates
End If
End If
End If
End If
End If
End Function