Option Explicit
Sub LomaParse()
Application.SendKeys "^g ^a {DEL}" 'Clears the Immediate Window
Application.ScreenUpdating = False
Dim CalcBook As Workbook 'R:\AMTRAK\AMTRAK System Integrator- 2010\99_User - Working files\Carlo\WIU Calculator.xlsm
Dim CalcSht As Worksheet 'Main Calculator worksheet defined as object
Dim LastRow As Long 'Last row of route data
Dim IXLName_Loma As String 'Next Interlocking for LoMA calculations
Dim ChainVal As Long 'Chaining values returned from Signal and Switch Parse
Dim SearchType As Integer '
Dim EncValue As Integer
Dim StuckInLoop As Boolean
StuckInLoop = True
Set CalcBook = Workbooks("WIU Calculator.xlsm")
CalcBook.Activate
Set CalcSht = CalcBook.Worksheets("WIU Calculator")
CalcSht.Select
If LomaCalled = False Then
CalcSht.Range("AS3:AS304").ClearContents 'Clear the LoMA Chaining Columns
CalcSht.Range("AV3:AY304").ClearContents 'Clear the LoMA Data Columns
End If
LineNum = CalcSht.Cells(1, 3).Value 'Cell (1,3) is C3
LastRow = CalcSht.Cells(CalcSht.Rows.Count, "F").End(xlUp).Row
'There are two possible run conditions: As standalone, or called from DataPull.
'LomaParse will be called if there is a signal in the "LoMA signal" cell of a particular row.
'If it was called, then it must only return data for the row specified.
'Otherwise, if run as standalone, it must run row by row for the entire worksheet.
If LomaCalled = False Then
RowVar = 3
Debug.Print "LomaParse was run in STANDALONE mode"
Else
If LomaCalled = True Then
Debug.Print "LomaParse was run in CALLED mode"
End If
End If
While StuckInLoop = True
LomaSig = CalcSht.Cells(RowVar, 41) 'Column 41(AO)
If LomaSig <> "" Then
If LomaSig <> "X" Then
'***
IXLName_Loma = CalcSht.Cells(RowVar, 5) 'Column 5(E)
Call DataPull.SignalParse(LineNum, IXLName_Loma, LomaSig, ChainVal)
CalcSht.Select
CalcSht.Cells(RowVar, 45) = ChainVal
SearchType = 2 'Pull LoMA Signal Next Radio Channel ID
Call DataPull.EncoderParse(LineNum, SearchType, IXLName_Loma, LomaSig, EncValue)
CalcSht.Select
CalcSht.Cells(RowVar, 48) = EncValue 'Column 48(AV)
SearchType = 1 'Pull LoMA Signal Next BCP/WIU Sector ID Number
Call DataPull.EncoderParse(LineNum, SearchType, IXLName_Loma, LomaSig, EncValue)
CalcSht.Select
CalcSht.Cells(RowVar, 49) = EncValue 'Column 49(AW)
SearchType = 3 'Pull LoMA Signal Next Encoder/WIU Assignment Number
Call DataPull.EncoderParse(LineNum, SearchType, IXLName_Loma, LomaSig, EncValue)
CalcSht.Select
CalcSht.Cells(RowVar, 50) = EncValue 'Column 50(AX)
SearchType = 4 'Pull LoMA Signal Next Track Number
Call DataPull.EncoderParse(LineNum, SearchType, IXLName_Loma, LomaSig, EncValue)
CalcSht.Select
CalcSht.Cells(RowVar, 51) = EncValue 'Column 51(AY)
'***
If LomaCalled = True Then
StuckInLoop = False
End If
Debug.Print "X Route"
End If
Debug.Print "BLANK Route"
End If
RowVar = RowVar + 1
If RowVar > LastRow Then
StuckInLoop = False
End If
Wend
End Sub