经纬仪测量小软件的问题
经纬仪测量小软件的问题:EXCEL表里有相应的计算CJ和GC的代码如下:
CJ=C3*(D3-F3)*COS(RADIANS((90-(G3+(H3/60)+(I3/3600)))))*COS(RADIANS((90-(G3+(H3/60)+(I3/3600)))))
GC=0.5*C3*(D3-F3)*SIN(RADIANS((2*(90-(G3+(H3/60)+(I3/3600))))))+(A3+B3)-E3
我自己又做了个经纬仪测量工具来计算计算CJ和GC,用起来可能比EXCEL表好用些;
经过实际数值来测试,CJ的数据值计算都正确,但是GC的计算仍然不正确。
查看EXCEL表里的公式:
CJ=C3*(D3-F3)*COS(RADIANS((90-(G3+(H3/60)+(I3/3600)))))*COS(RADIANS((90-(G3+(H3/60)+(I3/3600)))))
GC=0.5*C3*(D3-F3)*SIN(RADIANS((2*(90-(G3+(H3/60)+(I3/3600))))))+(A3+B3)-E3
和自己编写的VB代码里计算代码(代码如下:)进行比较:实在找不到语法错在哪?
Dim a, aa, b, bb, c, cc, d, dd, f, ff, g, l, gg, m, mm, ss, zz, xx, cj As Long
Dim zh, cz, yg, spd, gaocha, gc, ggcc, gach, ssppdd As Long
zh = Val(Text1.Text)
cz = Val(Text2.Text)
yg = Val(Text3.Text)
dd = Val(Text7.Text)
ff = Val(Text8.Text)
mm = Val(Text9.Text)
ss = Val(Text4.Text)
zz = Val(Text5.Text)
xx = Val(Text6.Text)
l = ss - xx
dd = dd / 180
ff = ff / 60 / 180
mm = mm / 3600 / 180
c = dd + mm + ff
g = c * 3.1415926
spd = 100 * l * Sin(g) * Sin(g)
gc = cz + 100 * l * Sin(g) * Cos(g) + yg - zz
If Val(spd * 10) > Int(Val(spd * 10)) + 0.4 Then
Text11.Text = Int(spd * 10 + 1) / 10
Else: Text11.Text = Int(Val(spd * 10)) / 10
End If
If Val(gc * 10) > Int(Val(gc * 10)) + 0.4 Then
Text12.Text = Int(gc * 10 + 1) / 10
Else: Text12.Text = Int(Val(gc * 10)) / 10
End If
End Sub
只好列上全部代码如下,供高手参考:
Option Explicit
Public appdisk As String
Private conn As ADODB.Connection
Private Rst As New ADODB.Recordset
Private Sub Command2_Click()
End
End Sub
Private Sub Command1_Click()
Dim sXLSPath As String
Dim s As String
Dim i As Integer
Dim myexcel As New Excel.Application
Dim mybook As New Excel.Workbook
Dim mysheet As New Excel.Worksheet
Set mybook = myexcel.Workbooks.Add '添加一个新的BOOK
Set mysheet = mybook.Worksheets.Add '添加一个新的SHEET
myexcel.Visible = True
myexcel.UserControl = True
' myexcel.Visible = False
If (Rst.State = adStateOpen) Then
Rst.Close
End If
Rst.CursorLocation = adUseClient
Rst.Open "Select * From cl3", conn, adOpenKeyset, adLockPessimistic
Rst.AddNew
Rst.Fields("zh").Value = Text1.Text
Rst.Fields("cz").Value = Text2.Text
Rst.Fields("yg").Value = Text3.Text
Rst.Fields("dd").Value = Text4.Text
Rst.Fields("ff").Value = Text5.Text
Rst.Fields("mm").Value = Text6.Text
Rst.Fields("ss").Value = Text7.Text
Rst.Fields("zz").Value = Text8.Text
Rst.Fields("xx").Value = Text9.Text
Rst.Fields("spd").Value = Text11.Text
Rst.Fields("gc").Value = Text12.Text
Rst.Update
MsgBox ("保存成功!")
Text1.SetFocus
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
Text5.Text = ""
Text6.Text = ""
Text7.Text = ""
Text8.Text = ""
Text9.Text = ""
Text11.Text = ""
Text12.Text = ""
For i = 1 To Rst.Fields.Count
mysheet.Cells(1, i).Value = Rst.Fields(i - 1).Name
Next i
mysheet.Cells(2, 1).CopyFromRecordset Rst
mybook.SaveAs (1)
Set mysheet = Nothing
Set mybook = Nothing
Set myexcel = Nothing
MsgBox "转换数据成功!"
End Sub
Private Sub Command3_Click()
Dim a, aa, b, bb, c, cc, d, dd, f, ff, g, l, gg, m, mm, ss, zz, xx, cj As Long
Dim zh, cz, yg, spd, gaocha, gc, ggcc, gach, ssppdd As Long
zh = Val(Text1.Text)
cz = Val(Text2.Text)
yg = Val(Text3.Text)
dd = Val(Text7.Text)
ff = Val(Text8.Text)
mm = Val(Text9.Text)
ss = Val(Text4.Text)
zz = Val(Text5.Text)
xx = Val(Text6.Text)
l = ss - xx
dd = dd / 180
ff = ff / 60 / 180
mm = mm / 3600 / 180
c = dd + mm + ff
g = c * 3.1415926
spd = 100 * l * Sin(g) * Sin(g)
gc = cz + 100 * l * Sin(g) * Cos(g) + yg - zz
If Val(spd * 10) > Int(Val(spd * 10)) + 0.4 Then
Text11.Text = Int(spd * 10 + 1) / 10
Else: Text11.Text = Int(Val(spd * 10)) / 10
End If
If Val(gc * 10) > Int(Val(gc * 10)) + 0.4 Then
Text12.Text = Int(gc * 10 + 1) / 10
Else: Text12.Text = Int(Val(gc * 10)) / 10
End If
Command1.SetFocus
End Sub
Private Sub Form_Load()
Dim ConString As String
ConString = "Provider=Microsoft.Jet.OleDb.4.0;Persist Security Info = False;" _
& "Data Source =" & App.Path & "\cl.mdb"
Set conn = CreateObject("ADODB.Connection")
With conn
.ConnectionString = ConString
.Open
End With
Rst.CursorLocation = adUseClient
Rst.Open "Select * From cl3", conn, adOpenKeyset, adLockPessimistic, adCmdText
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
Text5.Text = ""
Text6.Text = ""
Text7.Text = ""
Text8.Text = ""
Text9.Text = ""
Text11.Text = ""
Text12.Text = ""
End Sub
Private Sub Text9_Change()
Dim a, aa, b, bb, c, cc, d, dd, f, ff, g, l, gg, m, mm, ss, zz, xx, cj As Long
Dim zh, cz, yg, spd, gaocha, gc, ggcc, gach, ssppdd As Long
zh = Val(Text1.Text)
cz = Val(Text2.Text)
yg = Val(Text3.Text)
dd = Val(Text7.Text)
ff = Val(Text8.Text)
mm = Val(Text9.Text)
ss = Val(Text4.Text)
zz = Val(Text5.Text)
xx = Val(Text6.Text)
l = ss - xx
dd = dd / 180
ff = ff / 60 / 180
mm = mm / 3600 / 180
c = dd + mm + ff
g = c * 3.1415926
spd = 100 * l * Sin(g) * Sin(g)
gaocha = spd * Sin(g) * Cos(g)
gc = cz + gaocha + yg - zz
If Val(spd * 10) > Int(Val(spd * 10)) + 0.4 Then
Text11.Text = Int(spd * 10 + 1) / 10
Else: Text11.Text = Int(Val(spd * 10)) / 10
End If
If Val(gc * 10) > Int(Val(gc * 10)) + 0.4 Then
Text12.Text = Int(gc * 10 + 1) / 10
Else: Text12.Text = Int(Val(gc * 10)) / 10
End If
End Sub