Code:
Public Sub DelanoFullscaleStatus2(strTableName As String, intUnitNumStatus As Long)
Dim intRowCounter As Long
Dim intRowStart As Long
Dim dteBRStart As Date
Dim dteBREnd As Date
Dim dteBFStart As Date
Dim dteBFStop As Date
Dim intBRRunCounter As Integer
Dim intBFRunCounter As Integer
Dim intBROnlineCounter As Long
Dim intBFOnlineCounter As Long
Dim sngRunTime As Single
Dim blnBRBW As Boolean
Dim blnBFBW As Boolean
Dim blnOffline As Boolean
Dim blnWrite As Boolean
Dim strWhat As String
Dim sngUnitVol As Single
Dim intWhatBW As Integer 'variable used to keep track of what backwashed. '1 = BR, 2 = BF, 3 = Both
On Error GoTo ErrorHandler
'To do this, use a DAO Recordset and workspace, which would drastically improve performance.
Dim wkspDAO As DAO.Workspace
'Open the database
Set dbProformance = CurrentDb
Set wkspDAO = DBEngine.Workspaces(0)
strSQL = "SELECT " & strTableName & "_LS_ref.numVol FROM " & strTableName & "_LS_ref " _
& "WHERE " & strTableName & "_LS_ref.strLSTableName = '" & strTableName & "_U" & intUnitNumStatus & "';"
'debug.print strSQL
Set RS = dbProformance.OpenRecordset(strSQL)
If RS.EOF = True And RS.BOF = True Then 'The RS has nothing in it and you need to add the first process/facility.
'Little sister table is empty.
MsgBox "There is no data to analyze. Please import data before continuing.", vbOKOnly
Exit Sub
Else
sngUnitVol = RS.Fields(0) * 7.48 'cu. ft. to gallon conversion.
End If
Set RS = Nothing
'First task is to open the little sister table and populate a recordset.
strSQL = "SELECT dteTimeStamp, txtStatus, txtMode, col_U" & intUnitNumStatus & "_Q_EFF, col_U" & intUnitNumStatus & "_Q_IN, " _
& "col_U" & intUnitNumStatus & "_Q_BW_EFF, col_U" & intUnitNumStatus & "_RT_BR, " _
& "col_U" & intUnitNumStatus & "_RT_BF, intBRRunCounter, intBFRunCounter, " _
& "col_U" & intUnitNumStatus & "_EBCT,col_U" & intUnitNumStatus & "_NO3_BlendEff, " _
& "col_U" & intUnitNumStatus & "_Cl2Resid_ContactPipe, calc_U" & intUnitNumStatus & "_CT_ContactPipe, " _
& "calc_U" & intUnitNumStatus & "_Vol_BW_EFF, calc_U" & intUnitNumStatus & "_Vol_FTW, " _
& "calc_U" & intUnitNumStatus & "_Vol_Treated,col_U" & intUnitNumStatus & "_Q_BW_IN, " _
& "calc_U" & intUnitNumStatus & "_Vol_Dist, calc_U" & intUnitNumStatus & "_Vol_Bypassed, calc_U" & intUnitNumStatus & "_Vol_WellDisc, " _
& "calc_U" & intUnitNumStatus & "_Vol_BW_IN, calc_U" & intUnitNumStatus & "_CT_Required, col_U" & intUnitNumStatus & "_Temp_ContactPipe, " _
& "col_U" & intUnitNumStatus & "_Pres_DistSys, col_U" & intUnitNumStatus & "_Pres_BF_Eff " _
& "FROM " & strTableName & "_U" & intUnitNumStatus & " ORDER BY dteTimeStamp ASC;"
'debug.print strSQL
Set RS = dbProformance.OpenRecordset(strSQL)
If RS.EOF = True And RS.BOF = True Then 'The RS has nothing in it and you need to add the first process/facility.
'Little sister table is empty.
MsgBox "There is no data to analyze. Please import data before continuing.", vbOKOnly
Exit Sub
Else
RS.MoveLast
RS.MoveFirst
lngRowCount = RS.RecordCount
End If
'Then evaluate each row in the record set.
blnBRBW = True 'Assume it backwashed the first run so the program recognizes the first date.
blnBFBW = True 'Assume it backwashed the first run so the program recognizes the first date.
intBRRunCounter = 1
intBFRunCounter = 1
wkspDAO.BeginTrans
For lngIndex1 = 1 To lngRowCount 'may need to change start to 0 if RS is zero bound.
With RS
.Edit
Select Case True
Case ((.Fields(3).Value > 20) And (.Fields(5).Value = 0) And (.Fields(4).Value <> 0) And (.Fields(4).Value > 20))
'System just came online.
.Fields(1).Value = "Online"
blnOffline = False
intRowStart = lngIndex1
If blnBRBW = True And intBROnlineCounter > 623 Then '52 hours in 5 minute intervals
intBROnlineCounter = 0
blnBRBW = False
dteBRStart = .Fields(0).Value
ElseIf blnBRBW = True Then
intBROnlineCounter = intBROnlineCounter + 1
blnBRBW = False
dteBRStart = .Fields(0).Value
Else
intBROnlineCounter = intBROnlineCounter + 1
End If
If blnBFBW = True And intBFOnlineCounter > 864 Then '72 hours in 5 minute intervals
intBFOnlineCounter = 0
blnBFBW = False
dteBFStart = .Fields(0).Value
ElseIf blnBFBW = True Then
intBFOnlineCounter = intBFOnlineCounter + 1
blnBFBW = False
dteBFStart = .Fields(0).Value
Else
intBFOnlineCounter = intBFOnlineCounter + 1
End If
'Next, I need to determine the mode of operation.
Select Case .Fields(4).Value >= (1.1 * CSng((.Fields(3).Value) + CSng(.Fields(17).Value)))
Case True
If Len(.Fields(25).Value) > 0 Then
Select Case .Fields(24).Value >= (1.1 * CSng(.Fields(25).Value))
Case False
.Fields(2).Value = "Production"
.Fields(13).Value = .Fields(12).Value * 650 * 0.6 / .Fields(3).Value
Select Case .Fields(23).Value
Case 0
.Fields(22).Value = 0
Case 0.1 To 5
.Fields(22).Value = 12
Case 5 To 9.9
.Fields(22).Value = 8
Case 10 To 14.9
.Fields(22).Value = 6
Case 15 To 19.9
.Fields(22).Value = 4
Case 20 To 25
.Fields(22).Value = 3
Case Is > 25
.Fields(22).Value = 2
End Select
.Fields(18).Value = ((.Fields(3).Value - .Fields(17).Value) * 5) 'Distribution Volume at that time.
.Fields(19).Value = ((.Fields(4).Value - .Fields(3).Value - .Fields(17).Value) * 5) 'Bypassed volume.
If .Fields(11).Value <= 2 Then
.Fields(11).Value = 0 'Assumes if nitrate is less than 2 it is likely in error.
End If
Case Else
.Fields(2).Value = "Blended Flushing"
.Fields(15).Value = ((.Fields(3).Value - .Fields(17).Value) * 5) 'Filter-to-Waste Volume at that time.
.Fields(19).Value = ((.Fields(4).Value - .Fields(3).Value - .Fields(17).Value) * 5) 'Bypassed volume.
.Fields(13).Value = 0
.Fields(22).Value = 0
End Select
Else
.Fields(2).Value = "Production"
.Fields(13).Value = .Fields(12).Value * 650 * 0.6 / .Fields(3).Value
Select Case .Fields(23).Value
Case 0
.Fields(22).Value = 0
Case 0.1 To 5
.Fields(22).Value = 12
Case 5 To 9.9
.Fields(22).Value = 8
Case 10 To 14.9
.Fields(22).Value = 6
Case 15 To 19.9
.Fields(22).Value = 4
Case 20 To 25
.Fields(22).Value = 3
Case Is > 25
.Fields(22).Value = 2
End Select
.Fields(18).Value = ((.Fields(3).Value - .Fields(17).Value) * 5) 'Distribution Volume at that time.
.Fields(19).Value = ((.Fields(4).Value - .Fields(3).Value - .Fields(17).Value) * 5) 'Bypassed volume.
If .Fields(11).Value <= 2 Then
.Fields(11).Value = 0 'Assumes if nitrate is less than 2 it is likely in error.
End If
End If
Case Else
.Fields(2).Value = "Filter-to-Waste"
.Fields(15).Value = ((.Fields(3).Value - .Fields(17).Value) * 5) 'Filter-to-Waste Volume at that time.
.Fields(13).Value = 0
.Fields(22).Value = 0
End Select
.Fields(21).Value = .Fields(17).Value * 5 'Backwash Storage volume from well at that time.
.Fields(20).Value = .Fields(4).Value * 5 'Discharge volume from well at that time.
.Fields(16).Value = .Fields(3).Value * 5 'Treated volume at that time.
blnWrite = True
Case (.Fields(3).Value > 20 And .Fields(5).Value = 0 And .Fields(4).Value = 0)
'System just came online.
.Fields(1).Value = "Online"
blnOffline = False
intRowStart = lngIndex1
If blnBRBW = True And intBROnlineCounter > 623 Then '52 hours in 5 minute intervals
intBROnlineCounter = 0
blnBRBW = False
dteBRStart = .Fields(0).Value
ElseIf blnBRBW = True Then
intBROnlineCounter = intBROnlineCounter + 1
blnBRBW = False
dteBRStart = .Fields(0).Value
Else
intBROnlineCounter = intBROnlineCounter + 1
End If
If blnBFBW = True And intBFOnlineCounter > 864 Then '72 hours in 5 minute intervals
intBFOnlineCounter = 0
blnBFBW = False
dteBFStart = .Fields(0).Value
ElseIf blnBFBW = True Then
intBFOnlineCounter = intBFOnlineCounter + 1
blnBFBW = False
dteBFStart = .Fields(0).Value
Else
intBFOnlineCounter = intBFOnlineCounter + 1
End If
'Next, I need to determine the mode of operation.
Select Case .Fields(4).Value >= (1.1 * (.Fields(3).Value + .Fields(17).Value))
Case True
If Len(.Fields(25).Value) > 0 Then
Select Case .Fields(24).Value >= (1.1 * CSng(.Fields(25).Value))
Case False
.Fields(2).Value = "Production"
.Fields(13).Value = .Fields(12).Value * 650 * 0.6 / .Fields(3).Value
Select Case .Fields(23).Value
Case 0
.Fields(22).Value = 0
Case 0.1 To 5
.Fields(22).Value = 12
Case 5 To 9.9
.Fields(22).Value = 8
Case 10 To 14.9
.Fields(22).Value = 6
Case 15 To 19.9
.Fields(22).Value = 4
Case 20 To 25
.Fields(22).Value = 3
Case Is > 25
.Fields(22).Value = 2
End Select
.Fields(18).Value = ((.Fields(3).Value - .Fields(17).Value) * 5) 'Distribution Volume at that time.
.Fields(19).Value = ((.Fields(4).Value - .Fields(3).Value - .Fields(17).Value) * 5) 'Bypassed volume.
If .Fields(11).Value <= 2 Then
.Fields(11).Value = 0 'Assumes if nitrate is less than 2 it is likely in error.
End If
Case Else
.Fields(2).Value = "Blended Flushing"
.Fields(15).Value = ((.Fields(3).Value - .Fields(17).Value) * 5) 'Filter-to-Waste Volume at that time.
.Fields(19).Value = ((.Fields(4).Value - .Fields(3).Value - .Fields(17).Value) * 5) 'Bypassed volume.
.Fields(13).Value = 0
.Fields(22).Value = 0
End Select
Else
.Fields(2).Value = "Production"
.Fields(13).Value = .Fields(12).Value * 650 * 0.6 / .Fields(3).Value
Select Case .Fields(23).Value
Case 0
.Fields(22).Value = 0
Case 0.1 To 5
.Fields(22).Value = 12
Case 5 To 9.9
.Fields(22).Value = 8
Case 10 To 14.9
.Fields(22).Value = 6
Case 15 To 19.9
.Fields(22).Value = 4
Case 20 To 25
.Fields(22).Value = 3
Case Is > 25
.Fields(22).Value = 2
End Select
.Fields(18).Value = ((.Fields(3).Value - .Fields(17).Value) * 5) 'Distribution Volume at that time.
.Fields(19).Value = ((.Fields(4).Value - .Fields(3).Value - .Fields(17).Value) * 5) 'Bypassed volume.
If .Fields(11).Value <= 2 Then
.Fields(11).Value = 0 'Assumes if nitrate is less than 2 it is likely in error.
End If
End If
Case Else
.Fields(2).Value = "Filter-to-Waste"
.Fields(13).Value = 0
.Fields(22).Value = 0
.Fields(15).Value = ((.Fields(3).Value - .Fields(17).Value) * 5) 'Filter-to-Waste Volume at that time.
End Select
.Fields(21).Value = .Fields(17).Value * 5 'Backwash Storage volume from well at that time.
.Fields(20).Value = .Fields(4).Value * 5 'Discharge volume from well at that time.
.Fields(16).Value = .Fields(3).Value * 5 'Treated volume at that time.
blnWrite = True
Case (.Fields(3).Value <= 0 And .Fields(5).Value = 0)
'System just went offline but has not yet backwashed.
.Fields(1).Value = "Offline"
blnOffline = True
blnWrite = True
Case (.Fields(3).Value <= 0 And .Fields(5).Value > 0) And (blnBRBW = False And blnBFBW = False)
blnOffline = True
'strWhat = funWhatBackwashed(lngIndex1, intBROnlineCounter, intBFOnlineCounter)
strWhat = funWhatBackwashed2(.Fields(0).Value, intBROnlineCounter, intBFOnlineCounter, strTableName, .Fields(6).Value, .Fields(7).Value)
Select Case strWhat
Case "Bioreactor"
'intBROnlineCounter = 0
.Fields(1).Value = "BW BR"
dteBREnd = .Fields(0).Value
blnBRBW = True
intWhatBW = 1 'variable used to keep track of what backwashed. '1 = BR, 2 = BF, 3 = Both
Case "Biofilter"
'intBFOnlineCounter = 0
.Fields(1).Value = "BW BF"
dteBFStop = .Fields(0).Value
blnBFBW = True
intWhatBW = 2 'variable used to keep track of what backwashed. '1 = BR, 2 = BF, 3 = Both
Case "Both"
'intBROnlineCounter = 0
'intBFOnlineCounter = 0
.Fields(1).Value = "BW Both"
dteBREnd = .Fields(0).Value
dteBFStop = .Fields(0).Value
blnBRBW = True
blnBFBW = True
intWhatBW = 3 'variable used to keep track of what backwashed. '1 = BR, 2 = BF, 3 = Both
End Select
.Fields(14).Value = (.Fields(5).Value - .Fields(17).Value) * 5 'Backwash volume at that time
If .Fields(14).Value > 10000 Then
.Fields(14).Value = 0
End If
blnWrite = False
Case (.Fields(5).Value > 0) And (blnBRBW = False And blnBFBW = False)
blnOffline = True
'strWhat = funWhatBackwashed(lngIndex1, intBROnlineCounter, intBFOnlineCounter)
strWhat = funWhatBackwashed2(.Fields(0).Value, intBROnlineCounter, intBFOnlineCounter, strTableName, .Fields(6).Value, .Fields(7).Value)
Select Case strWhat
Case "Bioreactor"
'intBROnlineCounter = 0
.Fields(1).Value = "BW BR"
dteBREnd = .Fields(0).Value
blnBRBW = True
intWhatBW = 1 'variable used to keep track of what backwashed. '1 = BR, 2 = BF, 3 = Both
Case "Biofilter"
'intBFOnlineCounter = 0
.Fields(1).Value = "BW BF"
dteBFStop = .Fields(0).Value
blnBFBW = True
intWhatBW = 2 'variable used to keep track of what backwashed. '1 = BR, 2 = BF, 3 = Both
Case "Both"
'intBROnlineCounter = 0
'intBFOnlineCounter = 0
.Fields(1).Value = "BW Both"
dteBREnd = .Fields(0).Value
dteBFStop = .Fields(0).Value
blnBRBW = True
blnBFBW = True
intWhatBW = 3 'variable used to keep track of what backwashed. '1 = BR, 2 = BF, 3 = Both
End Select
.Fields(14).Value = (.Fields(5).Value - .Fields(17).Value) * 5 'Backwash volume at that time
If .Fields(14).Value > 10000 Then
.Fields(14).Value = 0
End If
blnWrite = False
Case Else
'Something else happened
.Fields(1).Value = "Unknown"
blnWrite = False
blnOffline = True
End Select
If blnOffline = True Then
'This empties out the flow rates when the system is offline. Need to empty out everything else as well, but do that separately.
.Fields(3).Value = Null
.Fields(4).Value = Null
.Fields(13).Value = Null
.Fields(22).Value = Null
Else 'Its online so please write everything else.
.Fields(6).Value = intBROnlineCounter * 5 / 60
.Fields(7).Value = intBFOnlineCounter * 5 / 60
.Fields(8).Value = intBRRunCounter
.Fields(9).Value = intBFRunCounter
If RS.Fields(3).Value <> 0 Then
.Fields(10).Value = sngUnitVol / RS.Fields(3).Value
Else
.Fields(10).Value = Null
End If
If intWhatBW <> 0 Then 'variable used to keep track of what backwashed. '1 = BR, 2 = BF, 3 = Both
If intWhatBW = 1 Then
intBRRunCounter = intBRRunCounter + 1
ElseIf intWhatBW = 2 Then
intBFRunCounter = intBFRunCounter + 1
ElseIf intWhatBW = 3 Then
intBRRunCounter = intBRRunCounter + 1
intBFRunCounter = intBFRunCounter + 1
End If
intWhatBW = 0
End If
End If
.Update
End With
'Then after 1000 rows, update status bar progress
If (lngIndex1 Mod 1000) = 0 Then
'Update the progressbar
modConfig.updStatusBarProgress (lngIndex1) 'turn this back on after testing.
wkspDAO.CommitTrans dbForceOSFlush
wkspDAO.BeginTrans
End If
RS.MoveNext
Next lngIndex1
Erase strarStatusData()
wkspDAO.CommitTrans dbForceOSFlush
wkspDAO.Close
'RS.Close
'dbProformance.Close
Set wkspDAO = Nothing
Set RS = Nothing
Set dbProformance = Nothing
Call modAnalysis.DelanoFullScaleZeroOffline(strTableName & "_U" & intUnitNumStatus, intUnitNumStatus)
ErrorHandler:
'debug.print Error(Err)
'MsgBox "Error occurred during raw unit locator writing. Error = " & Error(Err), vbOKOnly
If Error(Err) = "Invalid use of Null" Then
Resume Next
ElseIf Error(Err) = "Type Mismatch" Then
Resume Next
Else
'debug.print Error(Err)
ErrorReport.rcsErr = Err
ErrorReport.rcsErrDesc = Error(Err)
ErrorReport.rcsProcedure = "DelanoFullscaleStatus2" 'Edit per procedure
If ErrorReport.rcsErr = 0 Then
ErrorReport.rcsProcTrail = ErrorReport.rcsProcTrail & ErrorReport.rcsProcedure & ", Successful (" & ReturnVirtualMemory / 1024 / 1024 & " MB); "
Exit Sub
Else
ErrorReport.rcsProcTrail = ErrorReport.rcsProcTrail & ErrorReport.rcsProcedure & ", Failed (" & ReturnVirtualMemory / 1024 / 1024 & " MB); "
'ErrorReport.rcsErrLine = Erl
End If
ReDim ErrorReport.rcsVariables(1 To 21) 'Edit this end following block per procedure
ErrorReport.rcsVariables(1) = "(Passed) strTableName = " & strTableName
ErrorReport.rcsVariables(2) = "(Passed) intUnitNumStatus = " & intUnitNumStatus
ErrorReport.rcsVariables(3) = "(Dim) intRowCounter = " & intRowCounter
ErrorReport.rcsVariables(4) = "(Dim) intRowStart = " & intRowStart
ErrorReport.rcsVariables(5) = "(Dim) dteBRStart = " & dteBRStart
ErrorReport.rcsVariables(6) = "(Dim) dteBREnd = " & dteBREnd
ErrorReport.rcsVariables(7) = "(Dim) dteBFStart = " & dteBFStart
ErrorReport.rcsVariables(8) = "(Dim) dteBFStop = " & dteBFStop
ErrorReport.rcsVariables(9) = "(Dim) intBRRunCounter = " & intBRRunCounter
ErrorReport.rcsVariables(10) = "(Dim) intBFRunCounter = " & intBFRunCounter
ErrorReport.rcsVariables(11) = "(Dim) intBROnlineCounter = " & intBROnlineCounter
ErrorReport.rcsVariables(12) = "(Dim) intBFOnlineCounter = " & intBFOnlineCounter
ErrorReport.rcsVariables(13) = "(Dim) sngRunTime = " & sngRunTime
ErrorReport.rcsVariables(14) = "(Dim) blnBRBW = " & blnBRBW
ErrorReport.rcsVariables(15) = "(Dim) blnBFBW = " & blnBFBW
ErrorReport.rcsVariables(16) = "(Dim) blnOffline = " & blnOffline
ErrorReport.rcsVariables(17) = "(Dim) blnWrite = " & blnWrite
ErrorReport.rcsVariables(18) = "(Dim) strWhat = " & strWhat
ErrorReport.rcsVariables(19) = "(Dim) sngUnitVol = " & sngUnitVol
ErrorReport.rcsVariables(20) = "(Global) strSQL = " & strSQL
ErrorReport.rcsVariables(21) = "(Global) strStatusData = " & strStatusData
Call modConfig.ErrorReportOutput
End If
End Sub