请教,用VB写程序时,遇到ATN函数的时候就提示溢出,这是怎么回事啊
Private Sub Command1_Click()Dim d, d1, d2, d3, f, f1, f2, f3, r As Double
x = (N + c0) * Cos(a0) * Cos(b0)
y = (N + c0) * Cos(a0) * Sin(b0)
z = (N * (1 - e2) + c0) * Sin(b0)
r = Sqr(x * x + y * y + z * z)
d = Atn(z / Sqr(x * x + y * y)) 遇到这一行就不对了 这是怎么回事
f = Atn(y / x)
d1 = Int(d * 180 / pi)
d2 = Int((d * 180 / pi - d1) * 10800 / pi)
d3 = Int(((d * 180 / pi - d1) * 10800 / pi - d2) * 648000 / pi)
f1 = Int(f * 180 / pi)
f2 = Int((f * 180 / pi - f1) * 10800 / pi)
f3 = Int(((f * 180 / pi - f1) * 10800 / pi - f2) * 648000 / pi)
Text8.Text = d1
Text9.Text = d2
Text10.Text = d3
Text11.Text = f1
Text12.Text = f2
Text13.Text = f3
Text14.Text = r
End Sub
Private Sub Command2_Click()
Dim x1, y1, z1 As Double
Dim p, pd, p1, p2, p3, o, o1, o2, o3, q As Double
x1 = z * Cos(m0) * Cos(n0)
y1 = z * Cos(mo) * Sin(n0)
z1 = z * Sin(mo)
p = Atn(z1 / Sqr(x1 * x1 + y1 * y1))
pd = Atn((z1 + N * e2 * Sin(p)) / Sqr(x1 * x1 + y1 * y1))
If Abs(p - pd) < 0.05 Then
p = pd
pd = Atn((z1 + N * e2 * Sin(p)) / Sqr(x1 * x1 + y1 * y1))
End If
o = Atn(y1 / x1)
q = (Sqr(x1 * x1 + y1 * y1) / Cos(p)) - N
p1 = Int(p * 180 / pi)
p2 = Int((p * 180 / pi - p1) * 10800 / pi)
p3 = Int(((p * 180 / pi - p1) * 10800 / pi - p2) * 648000 / pi)
o1 = Int(o * 180 / pi)
o2 = Int((o * 180 / pi - o1) * 10800 / pi)
o3 = Int(((o * 180 / pi - o1) * 10800 / pi - o2) * 648000 / pi)
Text22.Text = p1
Text23.Text = p2
Text24.Text = p3
Text25.Text = o1
Text26.Text = o2
Text27.Text = o3
Text28.Text = q
End Sub
Private Sub Command3_Click()
Text1.SetFocus
End Sub
Private Sub Command4_Click()
Text15.SetFocus
End Sub
Private Sub Form2_Load()
Dim a0, a1, a2, a3, b0, b1, b2, b3, c0 As Double
Dim m0, m1, m2, m3, n0, n1, n2, n3, z As Double
Dim x, y, z As Double
Const pi = 3.14159265
Const a As Double = 6378137
Const b As Double = 6356752.3142
Const e2 As Double = 0.0066943799013
Dim N As Double
N = a / Sqr(1 - e2 * Sin(b0) * Sin(b0))
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 9 Then
a = pi * Val(Text1.Text) / 180
Text2.SetFocus
End If
End Sub
Private Sub Text15_KeyPress(KeyAscii As Integer)
If KeyAscii = 9 Then
m1 = pi * Val(Text15.Text) / 180
Text16.SetFocus
End If
End Sub
Private Sub Text16_KeyPress(KeyAscii As Integer)
If KeyAscii = 9 Then
m2 = pi * Val(Text16.Text) / 10800
Text17.SetFocus
End If
End Sub
Private Sub Text17_KeyPress(KeyAscii As Integer)
If KeyAscii = 9 Then
m3 = pi * Val(Text17.Text) / 648000
m0 = m1 + m2 + m3
Text18.SetFocus
End If
End Sub
Private Sub Text18_KeyPress(KeyAscii As Integer)
If KeyAscii = 9 Then
n1 = pi * Val(Text18.Text) / 180
Text19.SetFocus
End If
End Sub
Private Sub Text19_KeyPress(KeyAscii As Integer)
If KeyAscii = 9 Then
n2 = pi * Val(Text19.Text) / 10800
Text20.SetFocus
End If
End Sub
Private Sub Text2_KeyPress(KeyAscii As Integer)
If KeyAscii = 9 Then
a2 = pi * Val(Text2.Text) / 10800
Text3.SetFocus
End If
End Sub
Private Sub Text20_KeyPress(KeyAscii As Integer)
If KeyAscii = 9 Then
n3 = pi * Val(Text20.Text) / 648000
n0 = n1 + n2 + n3
Text21.SetFocus
End If
End Sub
Private Sub Text21_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
z = Val(Text21.Text)
End If
End Sub
Private Sub Text3_KeyPress(KeyAscii As Integer)
If KeyAscii = 9 Then
a3 = pi * Val(Text3.Text) / 648000
a0 = a1 + a2 + a3
Text4.SetFocus
End If
End Sub
Private Sub Text4_KeyPress(KeyAscii As Integer)
If KeyAscii = 9 Then
b1 = pi * Val(Text4.Text) / 180
Text5.SetFocus
End If
End Sub
Private Sub Text5_KeyPress(KeyAscii As Integer)
If KeyAscii = 9 Then
b2 = pi * Val(Text5.Text) / 10800
Text6.SetFocus
End If
End Sub
Private Sub Text6_KeyPress(KeyAscii As Integer)
If KeyAscii = 9 Then
b3 = pi * Val(Text6.Text) / 648000
b0 = b1 + b2 + b3
Text7.SetFocus
End If
End Sub
Private Sub Text7_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
c0 = Text7.Text
End If
End Sub
VB 求助 --------------------编程问答-------------------- Dim d As Double, d1 As Double, d2 As Double, d3 As Double, f As Double, f1 As Double, f2 As Double, f3 As Double, r As Double --------------------编程问答-------------------- VB很垃圾,自作聪明地设计了很多简化语法,导致它充满陷阱,任何一个没有用过VB的程序员一开始使用它都会有一种被捉弄的感觉。
比如,VB允许你写Dim a,事实上是Dim a As Variant。而且VB又允许在一个语句里面定义多个类型,比如 Dim i As Integer, s As String。所以Dim a, b As Double为什么不对就很好理解了。
如果你想编写鲁棒的可靠的程序,尽快和VB说再见吧。 --------------------编程问答-------------------- Dim d As Double, d1 As Double, d2 As Double, d3 As Double, f As Double, f1 As Double, f2 As Double, f3 As Double, r As Double '变量必须每个指定类型
dim x As Double,y As Double,z As Double
--------------------编程问答-------------------- 各位大神,我觉得我的程序的问题是,在click事件发生的时候 变量没有传进去值 这是为什么啊?? --------------------编程问答-------------------- x = (N + c0) * Cos(a0) * Cos(b0)
y = (N + c0) * Cos(a0) * Sin(b0)
z = (N * (1 - e2) + c0) * Sin(b0)
r = Sqr(x * x + y * y + z * z)
d = Atn(z / Sqr(x * x + y * y))
看这段代码,N c0 a0在哪定义,在哪赋值?没有定义和赋值,VB将初始化为0,atn的除数为0,当然溢出 --------------------编程问答--------------------
对哦,你的初始化在哪?
而且你这样定义变量很不规范
Dim d, d1, d2, d3, f, f1, f2, f3, r As Double
应该
dim d as double
dim d1 as double
。。。。 --------------------编程问答-------------------- 抛开定义上的疏漏和毫无助益的变量名,
只是d = Atn(z / Sqr(x * x + y * y))这一句, 看到除法就要注意分母是否为0了.
最后还是要吐槽一句: 楼主你这代码哪抄来的? 还是换个成绩好点的抄吧.
补充:VB , 基础类