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

missing lines

Status
Not open for further replies.

swamy567

Programmer
Sep 18, 2008
24
US
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


 




Have you tried to STEP thru the loop to observe what is happening with the rows in question?

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Skip
thanks for your valuable and precious time. i did go through step there is no skiping code in above function. is there any other way to find out.
 
skip
when i step through it is not skippking it is printing. when i run it is skipping
 



I wan not referring to skipping code. You need to observe what is happening to the data content of variables at the point where the skip occurs.

Use the Watch Window.

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
SKIP!
Nothing showing in watch window when it comes on 08/22/08 fall in friday. it skips the below code and it goes to end if. strCurrent Day = friday.
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
 



...and...

what were the values in strNextDay and strAfterNextday

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 



Why do you continue to use that awful function???!

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
the whole thing has written in vb. i could modify in this only. could you please help me please.
 



It's just about this simple, unless I'm missing something...
Code:
Do While Not EOF(1)
  ' Read line into variable.
  sDate = Mid(variable, 15,8)
  if DateValue(sDate) <= LastWorkday(DateValue(sDate)) Then
     'process this record
  End if
loop


Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
skip
thanks a lot for your great help. but now it is missing whole month
 




AS you step thru your code, you will discover WHY this is happening as you observe the data values and control structure.

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
ok skip again you spent lot of time for me. thanks a lot. whcih variable should i check in watch window. so that i can check all variable in the function
 



swamy567 (Programmer)

As a "programmer" you ought to know how to debug your code. Your question is betraying your competance.

Skip,

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

Part and Inventory Search

Sponsor

Back
Top