D
Derek Wittman
Good morning,
I'm seriously challenged today to remember why I did some of the things in this code. I need to modify it for another part of the application (not a part of CigLogic functionality), and I cannot remember why I reset variables on which lines I did. Fortunately, I remember why I needed the movenexts and movepreviouses where they are. I thought I had enough commenting for myself, but I guess I am wrong. Can someone please give me a hand? Thank you very much in advance!
Derek
Code:
Sub CigLogic()
Dim dbs As DAO.Database, rstCumArm1 As DAO.Recordset
Dim curInter, curToCase, cur6s, cur2s, cur1s As Double
Dim previnter, curCumArm, nextCumArm As Integer
'Setting up the recordset
Set dbs = CurrentDb
Set rstCumArm1 = dbs.OpenRecordset("CumArm1", dbOpenTable)
With rstCumArm1
.MoveLast
.MoveFirst 'my record of 0's. I'm not working calculations on this one.
.MoveNext
While Not .EOF 'starting my loop (supposedly...)
curInter = 0 'reset curInter (why am I doing this inside the loop?)
.MovePrevious
previnter = !inter 'put (X-1) value of 'inter' field to previnter
.MoveNext
.MoveNext
If .EOF Then
nextCumArm = 0
Else: nextCumArm = !CumArm 'put (X+1) value of CumArm to nextCumArm
End If
.MovePrevious
If previnter + !CumArm + nextCumArm > 12 Then 'start making decisions - if TRUE then start putting from arm into case
curInter = 0
curToCase = previnter + !CumArm
cur6s = Int(curToCase / 6)
cur2s = Int((curToCase - cur6s * 6) / 2)
cur1s = curToCase - 6 * cur6s - 2 * cur2s
Else: curInter = previnter + !CumArm 'since it's not TRUE then continue to accummulate into arm
curToCase = 0
cur6s = 0
cur2s = 0
cur1s = 0
End If
.Edit 'time to start updating the recordset to the held variable values
!inter = curInter
!tocase = curToCase
![6s] = cur6s
![2s] = cur2s
![1s] = cur1s
!TimeSt = Now()
.Update 'time to move the values from the recordset to the datatable
.MoveNext
Wend 'supposedly to go back to the WHILE NOT start
.Close
End With
CurrentDb.Close
Set rstCumArm1 = Nothing
Set dbs = Nothing
DoCmd.RunSQL ("Delete * from CumArm1 where TimeSt = dmin('[TimeSt]','CumArm1','')")
End If
End Sub
I'm seriously challenged today to remember why I did some of the things in this code. I need to modify it for another part of the application (not a part of CigLogic functionality), and I cannot remember why I reset variables on which lines I did. Fortunately, I remember why I needed the movenexts and movepreviouses where they are. I thought I had enough commenting for myself, but I guess I am wrong. Can someone please give me a hand? Thank you very much in advance!
Derek
Code:
Sub CigLogic()
Dim dbs As DAO.Database, rstCumArm1 As DAO.Recordset
Dim curInter, curToCase, cur6s, cur2s, cur1s As Double
Dim previnter, curCumArm, nextCumArm As Integer
'Setting up the recordset
Set dbs = CurrentDb
Set rstCumArm1 = dbs.OpenRecordset("CumArm1", dbOpenTable)
With rstCumArm1
.MoveLast
.MoveFirst 'my record of 0's. I'm not working calculations on this one.
.MoveNext
While Not .EOF 'starting my loop (supposedly...)
curInter = 0 'reset curInter (why am I doing this inside the loop?)
.MovePrevious
previnter = !inter 'put (X-1) value of 'inter' field to previnter
.MoveNext
.MoveNext
If .EOF Then
nextCumArm = 0
Else: nextCumArm = !CumArm 'put (X+1) value of CumArm to nextCumArm
End If
.MovePrevious
If previnter + !CumArm + nextCumArm > 12 Then 'start making decisions - if TRUE then start putting from arm into case
curInter = 0
curToCase = previnter + !CumArm
cur6s = Int(curToCase / 6)
cur2s = Int((curToCase - cur6s * 6) / 2)
cur1s = curToCase - 6 * cur6s - 2 * cur2s
Else: curInter = previnter + !CumArm 'since it's not TRUE then continue to accummulate into arm
curToCase = 0
cur6s = 0
cur2s = 0
cur1s = 0
End If
.Edit 'time to start updating the recordset to the held variable values
!inter = curInter
!tocase = curToCase
![6s] = cur6s
![2s] = cur2s
![1s] = cur1s
!TimeSt = Now()
.Update 'time to move the values from the recordset to the datatable
.MoveNext
Wend 'supposedly to go back to the WHILE NOT start
.Close
End With
CurrentDb.Close
Set rstCumArm1 = Nothing
Set dbs = Nothing
DoCmd.RunSQL ("Delete * from CumArm1 where TimeSt = dmin('[TimeSt]','CumArm1','')")
End If
End Sub