Sub ProcessCTCReport() ' Dim dData(15) As Double, cData(15) As String Dim ScratchModel As String Dim iRet As Integer, lCounter As Long, lRet As Long Dim L As Long, L2 As Long Dim lNumstrgs As Long, lDisco As Long Dim iTotalPoints As Integer Dim cLabel As String Dim OffsetSide As Double Dim lXmin As Long, lYmin As Long, lXmax As Long, lYmax As Long Dim lNopts As Long, lNodim As Long Dim cSubRef As String, dClv As Double Dim cModels(1 To 4) As String Dim cFields(1 To 10) As String Dim fileID As Double, TextLine As String, Bit As String Dim FileInp As String, FileInp996 As String Dim FileOut As String, FileOut996 As String Dim MxForm As String Dim cLab As String Dim Satisfied As Boolean, NewString As Boolean Dim cCurveFit As String ScratchModel = "CTCREPORT SCRATCH MODEL" DesignModel = frmStart001.MOSSmod001.ModelName TriModel = frmStart001.MOSSmod002.ModelName SurvModel = frmStart001.MOSSmod003.ModelName RefString = frmStart001.MOSSstr001.StringName TriString = frmStart001.MOSSstr002.StringName cMask = frmStart001.MOSSstr003.StringName 'empty if mask table used If frmStart001.chkCurveFitting.Value = 1 Then cCurveFit = "CURV" Else cCurveFit = "NOCU" End If Template = Val(frmStart001.txtTemplate.Text) sToleranceLow = Val(frmStart001.txtTolLow.Text) sToleranceHigh = Val(frmStart001.txtTolHigh.Text) MxForm = "0.0000" 'format coordinates for Mx input fileID = Format(Now(), "ddmmyyhhmmss") FileInp = oMFWC.MFWProjectDir + "\CTCReport" + Str(fileID + 1) + ".inp" FileInp996 = oMFWC.MFWProjectDir + "\CTCReport 996" + Str(fileID + 1) + ".inp" FileOut = oMFWC.MFWProjectDir + "\CTCReport" + Str(fileID) + ".prn" FileOut996 = oMFWC.MFWProjectDir + "\CTCReport 996" + Str(fileID) + ".prn" Open FileInp For Output As #1 Print #1, "OUTPUT,"; FileOut Print #1, "DELETE,"; ScratchModel Print #1, "CREATE,"; ScratchModel Close #1 ' run input file cModels(1) = FileInp iRet = oMFWB.MFWFireMajor(cMOSSopt:="INPUT", cMOSSModels:=cModels()) Kill FileInp cModels(1) = SurvModel cModels(2) = ScratchModel iRet = oMFWB.MFWFireMajor(cMOSSopt:="COPY", cMOSSModels:=cModels()) If frmStart001.MOSSstr003.MaskEnabled = True Then 'use mask table iRet = oMFWB.MFWFireMasks Else 'use string mask cFields(1) = cMask End If iRet = oMFWB.MFWFireMinor(cMOSSopt:="060", cMOSSFields:=cFields()) iRet = oMFWB.MFWFire999 Open FileInp For Output As #1 Print #1, "REPORT,"; ScratchModel Print #1, "991" 'get number of strings and points Print #1, "999" Print #1, "OUTPUT" Close #1 ' run input file cModels(1) = FileInp iRet = oMFWB.MFWFireMajor(cMOSSopt:="INPUT", cMOSSModels:=cModels()) ' get number of points and dimension results array iRet = oMFWB.MFWGetData(1, dData, cData) lNumstrgs = dData(0) 'number of strings lTotalPoints = dData(1) 'number of points ReDim Results(0 To lTotalPoints) Kill FileOut Open FileInp For Output As #1 Print #1, "OUTPUT,"; FileOut Print #1, "SECTION,"; TriModel; ","; ScratchModel Print #1, "SECTION,"; ScratchModel Open FileInp996 For Output As #2 Print #2, "OUTPUT,"; FileOut996 Print #2, "REPORT,"; DesignModel; ","; ScratchModel Print #2, "017,"; cCurveFit iRet = oMFWB.MFWGetNoStrings(ScratchModel, cMask, lNumstrgs) 'needed to reset MFWGetStrings For L = 1 To lNumstrgs lRet = oMFWB.MFWGetStrings(ScratchModel, cMask, cLabel) Print #1, "177,"; cLabel; ","; TriString; ","; cLabel Print #2, "996,"; RefString; ",PLAN,"; cLabel; ",1" iRet = oMFWB.MFWGetIndex(ScratchModel, cLabel, lXmin, lYmin, lXmax, lYmax, lNopts, lNodim, cSubRef, dClv) For L2 = 1 To lNopts 'load survey strings into Results lCounter = lCounter + 1 iRet = oMFWB.MFWGetPoint(ScratchModel, cLabel, L2, dData, cData, lDisco) With Results(lCounter) .PointNo = L2 .StrLabel = cLabel .East = dData(0) .North = dData(1) .SurLevel = Format(dData(2), "0.000") End With iRet = Progress(lCounter, lTotalPoints) Next L2 Next L Print #1, "999" Print #1, "OUTPUT" Close #1 Print #2, "999" Print #2, "OUTPUT" Close #2 frmStart001.PicProgress.Visible = False 'hide progress bar frmStart001.lblMessage.Visible = True 'show progress message ' run input files cModels(1) = FileInp 'section through triangulation iRet = oMFWB.MFWFireMajor(cMOSSopt:="INPUT", cMOSSModels:=cModels()) cModels(1) = FileInp996 ' do 996 report iRet = oMFWB.MFWFireMajor(cMOSSopt:="INPUT", cMOSSModels:=cModels()) frmStart001.lblMessage.Visible = False 'hide progress message Kill FileInp Kill FileOut Kill FileInp996 For L = 1 To lTotalPoints ' get design level and level difference With Results(L) iRet = oMFWB.MFWGetPoint(ScratchModel, .StrLabel, .PointNo, dData, cData, lDisco) .DesLevel = Format(dData(2), "0.000") If .DesLevel <> -999 Then .DesLevel = .DesLevel + Template ' adjust for template depth .Diff = Format(.SurLevel - .DesLevel, "0.000") 'If Abs(.Diff) < 0.001 Then .Diff = 0# Else .Diff = 0# End If End With iRet = Progress(L, lTotalPoints) Next L lCounter = 0 ' reset counter Open FileOut996 For Input As #2 Do While Not EOF(2) ' Loop until end of file. Line Input #2, TextLine ' Read line into variable. Bit = Trim(Left(TextLine, 6)) Select Case Bit ' looking for NORMALS, RefLabel or Warning Case "NORMA" ' start of new string NewString = True Satisfied = False Case "PERPE" ' start of new point (may be duplicate if more than 2 normals) If Not NewString Then ' but not if start of new string If Trim(Mid(TextLine, 44, 13)) = Format(Results(lCounter).East, "0.000") And Trim(Mid(TextLine, 57, 13)) = Format(Results(lCounter).North, "0.000") Then Satisfied = True Else Satisfied = False End If Else Satisfied = False End If NewString = False Case "W799" ' no normal found lCounter = lCounter + 1 Results(lCounter).Station = -999 Results(lCounter).Offset = -999 Satisfied = False Case RefString ' normal found If Not Satisfied Then ' first normal for this point lCounter = lCounter + 1 Results(lCounter).Station = Val(Mid(TextLine, 84, 11)) Results(lCounter).Offset = Val(Mid(TextLine, 23, 9)) OffsetSide = Val(Mid(TextLine, 96, 3)) - Val(Mid(TextLine, 33, 3)) If OffsetSide < 0 Then OffsetSide = OffsetSide + 360 If OffsetSide > 180 Then Results(lCounter).Offset = Results(lCounter).Offset * -1 Else ' already got a normal for this point If Val(Mid(TextLine, 23, 9)) < Abs(Results(lCounter).Offset) Then 'closer so use this normal Results(lCounter).Station = Val(Mid(TextLine, 84, 11)) Results(lCounter).Offset = Val(Mid(TextLine, 23, 9)) OffsetSide = Val(Mid(TextLine, 96, 3)) - Val(Mid(TextLine, 33, 3)) If OffsetSide < 0 Then OffsetSide = OffsetSide + 360 If OffsetSide > 180 Then Results(lCounter).Offset = Results(lCounter).Offset * -1 Else 'ignore normal End If End If Satisfied = True Case Else 'rubbish string - carry on End Select iRet = Progress(lCounter, lTotalPoints) Loop Close #2 cModels(1) = ScratchModel ' delete scratch model iRet = oMFWB.MFWFireMajor(cMOSSopt:="DELETE", cMOSSModels:=cModels()) Kill FileOut996 End Sub