Public Class Form1 Dim n As Integer Dim startH, endH As Double Public Structure pt '定義站點資訊,包括站點名稱,前視兩次讀數,后視兩次讀書,高差,修正高差,站點距離' Dim HeightDifference As Double Dim ptname As String Dim length As Double Dim frontview1 As Double Dim frontview2 As Double Dim rearview1 As Double Dim rearview2 As Double Dim avgh As Double Dim updateh As Double End Structure Public p(20) As pt Public Sub readnum() '進行資料的讀入' Dim s As String If OpenFileDialog1.ShowDialog <> Windows.Forms.DialogResult.Cancel Then s = OpenFileDialog1.FileName End If FileOpen(1, s, OpenMode.Output) WriteLine(1, 3) WriteLine(1, "1", 5, 2, 3, 4, 5) WriteLine(1, "2", 6, 1, 3, 4, 5) WriteLine(1, "3", 5.5, 2, 4, 5, 6) FileClose() FileOpen(1, s, OpenMode.Input) Input(1, n) For i = 1 To n Input(1, p(i).ptname) Input(1, p(i).length) Input(1, p(i).frontview1) Input(1, p(i).frontview2) Input(1, p(i).rearview1) Input(1, p(i).rearview2) Next FileClose() End Sub 'Public Sub New(ByVal name As String, ByVal fv1 As Double, ByVal fv2 As Double, ByVal rv1 As Double, ByVal rv2 As Double, ByVal len As Double, ByVal hd As Double) 'End Sub Private Sub HeightComputation(ByRef a As pt) '通過前后視讀數來計算站點間的高程差' a.HeightDifference = (a.frontview1 - a.rearview1) + (a.frontview2 - a.rearview2) a.HeightDifference = a.HeightDifference / 2.0 End Sub Function TotalHeight(ByVal a() As pt) As Double '計算閉合高程差' Dim fsum As Double For i = 1 To n fsum += a(i).HeightDifference Next Return fsum End Function Function TotalLen(ByVal a() As pt) As Double '計算水準路線長度' Dim Lsum As Double For i = 1 To n Lsum += a(i).length Next Return Lsum End Function Private Sub UpdateHeight(ByRef a() As pt) '進行高差修正' Dim fhPermit, fh, Updatenum As Double fhPermit = 10 * Math.Sqrt(TotalLen(a)) fh = TotalHeight(a) - (startH - endH) If Math.Abs(fh) < Math.Abs(fhPermit) Then '大于還是小于?不小心改錯了,除錯時候注意下' Updatenum = fh / Math.Sqrt(TotalLen(a)) For i = 1 To n a(i).updateh = a(i).length * Updatenum a(i).HeightDifference = a(i).HeightDifference + a(i).updateh Next End If End Sub Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click readnum() For i = 1 To n HeightComputation(p(i)) Next UpdateHeight(p) For i = 1 To n MsgBox(p(i).updateh) Next End Sub
End Class
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/18429.html
標籤:VB基礎類
上一篇:求求幫個忙看看出了什么問題
