i am having script in vb6. when i click button it runs and should exclude last businessday onlybut it exclude other dates also. could you help in this regard.thanks a lot.
code isnhere:-
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:\Documents and Settings\My Documents\qty\QrtlyRateDel.txt"
LastDateRemoved = "C:\Documents and Settings\My Documents\qty\QrtlyRateExludeMEdate.txt" 'QrtlyRateDel.txt"
Open OriginalQRDfile For Input As #1
Open LastDateRemoved For Output As #2
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 InputRateRead, 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, InputRateRead
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 strNextDay = "Saturday" And strAfterNextday = "Sunday" Then
'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, InputRateRead
End If
End If
End If
End If
End If
End Function
code isnhere:-
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:\Documents and Settings\My Documents\qty\QrtlyRateDel.txt"
LastDateRemoved = "C:\Documents and Settings\My Documents\qty\QrtlyRateExludeMEdate.txt" 'QrtlyRateDel.txt"
Open OriginalQRDfile For Input As #1
Open LastDateRemoved For Output As #2
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 InputRateRead, 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, InputRateRead
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 strNextDay = "Saturday" And strAfterNextday = "Sunday" Then
'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, InputRateRead
End If
End If
End If
End If
End If
End Function