I am probably missing something obvious... but i need some help pointing out what is wrong.
The following code is supposed to fetch through the current table (associated with a form that has a button that triggers the code)
It steps through the table & creates records in another table based on the information in the current table.
dim tbl1 As P
dim tbl2 As P
dim TmpNumShips As N
dim tmpStartDate As D
dim tmpEndDate As D
dim PeriodInWeeks As N
dim DaysBetweenStartEnd As N
dim WeeksBetweenStartEnd As N
dim CountRecs As N
tbl1 = Table.current() ' tbl1 points to custconsumables
tbl2 = Table.Open("consumblesschedule",FILE_RW_EXCLUSIVE)
tbl1.fetch_first()
while .NOT.tbl1.eof()
'how many records will we need to create?
tmpEndDate = tbl1.EndDate
tmpStartDate = tbl1.StartDate
PeriodInWeeks = tbl1.Period
DaysBetweenStartEnd = tmpEndDate - tmpStartDate
WeeksBetweenStartEnd = DaysBetweenStartEnd / 7
TmpNumShips = abs(WeeksBetweenStartEnd / PeriodInWeeks)
'ok... we need to create TmpNumShips records
if TmpNumShips > 100 then
ui_msg_box("Number Of Shippments is >100 Customer# "+tbl1.Custnum, "Too many shipments ("+TmpNumShips+")",UI_STOP_SYMBOL+UI_OK)
stop
end
end if
for CountRecs = 0 to TmpNumShips
tbl2.enter_begin()
tbl2.custnum = tbl1.custnum
tbl2.productnum = tbl1.Productnum
tbl2.Price = tbl1.Price
tbl2.datetoship = tbl1.Startdate + (CountRecs * (PeriodInWeeks*7))
tbl2.nextdatetoship = tbl1.Startdate + (CountRecs * (PeriodInWeeks*7)) + PeriodInWeeks*7
tbl2.enter_end(.t.)
next
tbl1.change_begin()
tbl1.SCHEDULEUPDATED = .T.
tbl1.change_end(.T.)
tbl1.fetch_next()
end while
tbl2.close()
ui_msg_box("Consumables Scheduler Has Been Updated","Update was successful.",UI_INFORMATION_SYMBOL+UI_OK)
Everything is working except that it does not process the last record in tbl1???
If i understand how a while loop works the tbl1.fetch_next() statement should fetch the last record and not trigger an eof()
What am i missing??
The following code is supposed to fetch through the current table (associated with a form that has a button that triggers the code)
It steps through the table & creates records in another table based on the information in the current table.
dim tbl1 As P
dim tbl2 As P
dim TmpNumShips As N
dim tmpStartDate As D
dim tmpEndDate As D
dim PeriodInWeeks As N
dim DaysBetweenStartEnd As N
dim WeeksBetweenStartEnd As N
dim CountRecs As N
tbl1 = Table.current() ' tbl1 points to custconsumables
tbl2 = Table.Open("consumblesschedule",FILE_RW_EXCLUSIVE)
tbl1.fetch_first()
while .NOT.tbl1.eof()
'how many records will we need to create?
tmpEndDate = tbl1.EndDate
tmpStartDate = tbl1.StartDate
PeriodInWeeks = tbl1.Period
DaysBetweenStartEnd = tmpEndDate - tmpStartDate
WeeksBetweenStartEnd = DaysBetweenStartEnd / 7
TmpNumShips = abs(WeeksBetweenStartEnd / PeriodInWeeks)
'ok... we need to create TmpNumShips records
if TmpNumShips > 100 then
ui_msg_box("Number Of Shippments is >100 Customer# "+tbl1.Custnum, "Too many shipments ("+TmpNumShips+")",UI_STOP_SYMBOL+UI_OK)
stop
end
end if
for CountRecs = 0 to TmpNumShips
tbl2.enter_begin()
tbl2.custnum = tbl1.custnum
tbl2.productnum = tbl1.Productnum
tbl2.Price = tbl1.Price
tbl2.datetoship = tbl1.Startdate + (CountRecs * (PeriodInWeeks*7))
tbl2.nextdatetoship = tbl1.Startdate + (CountRecs * (PeriodInWeeks*7)) + PeriodInWeeks*7
tbl2.enter_end(.t.)
next
tbl1.change_begin()
tbl1.SCHEDULEUPDATED = .T.
tbl1.change_end(.T.)
tbl1.fetch_next()
end while
tbl2.close()
ui_msg_box("Consumables Scheduler Has Been Updated","Update was successful.",UI_INFORMATION_SYMBOL+UI_OK)
Everything is working except that it does not process the last record in tbl1???
If i understand how a while loop works the tbl1.fetch_next() statement should fetch the last record and not trigger an eof()
What am i missing??
Comment