| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2394 人关注过本帖
标题:程序运行时出现错误6“溢出”的提示,请问怎么解决?程序如下:
只看楼主 加入收藏
Hubertyang
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2017-11-28
收藏
 问题点数:0 回复次数:0 
程序运行时出现错误6“溢出”的提示,请问怎么解决?程序如下:
Private Sub OK_Click()
R1 = CDbl(Val(TextBox1.Text))
R2 = CDbl(Val(TextBox2.Text))
NN = Int(Val(TextBox3.Text))
cylHeight1 = CDbl(Val(TextBox4.Text))
cylHeight2 = CDbl(Val(TextBox5.Text))
x0 = CDbl(Val(TextBox6.Text))
y0 = CDbl(Val(TextBox7.Text))
z0 = CDbl(Val(TextBox8.Text))
UserForm1.Hide
ThisDrawing.creat3d
End Sub
Public Sub Data_Process()
Dim i As Integer
Const pi = 3.14159265
x0 = 900
y0 = 0
z0 = 200

DataFile = "C:\Users\Administrator\Desktop\VBAprojects\saddle5.txt"
DataFile1 = "C:\Users\Administrator\Desktop\VBAprojects\saddle51.txt"
DataFile2 = "C:\Users\Administrator\Desktop\VBAprojects\data.txt"
'以写入的方式打开数据文件
Open DataFile For Output As #1
Open DataFile1 For Output As #2
Open DataFile2 For Output As #3

For i = NN To 0 Step -1
XX = CSng(R2 * Cos((NN - i) * (pi / 100)) + cylHeight1 / 2)
YY = CSng(Sqr(R2 ^ 2 - (XX - cylHeight1 / 2) ^ 2))
ZZ = CSng(Sqr(R1 ^ 2 - YY ^ 2))
 
nx = (YY * ZZ)
ny = (-(XX - cylHeight1 / 2) * ZZ)
nz = ((XX - cylHeight1 / 2) * YY)
 
l1 = (YY ^ 2 + ZZ ^ 2) * (XX - cylHeight1 / 2)
m1 = YY * ZZ ^ 2
n1 = -1 * YY ^ 2 * ZZ
 
l2 = -1 * YY ^ 2 * (XX - cylHeight1 / 2)
m2 = YY * (XX - cylHeight1 / 2) ^ 2
n2 = ZZ * (XX - cylHeight1 / 2) ^ 2 + YY ^ 2 * ZZ
 
M = (Sqr(l1 ^ 2 + m1 ^ 2 + n1 ^ 2))
N = (Sqr(l1 ^ 2 + m1 ^ 2 + n1 ^ 2))
 
A1 = N * l1 - M * l2
B1 = N * m1 - M * m2
C1 = N * n1 - M * n2
 
A2 = nx
B2 = ny
C2 = nz
 
ax = -(B1 * C2 - B2 * C1)
ay = -(C1 * A2 - C2 * A1)
az = -(A1 * B2 - A2 * B1)
 
ox = -(ny * az - nz * ay)
oy = -(nz * ax - nx * az)
oz = -(nx * ay - ny * ax)

nx1 = CSng(nx / Sqr(nx ^ 2 + ny ^ 2 + nz ^ 2))
ny1 = CSng(ny / Sqr(nx ^ 2 + ny ^ 2 + nz ^ 2))
nz1 = CSng(nz / Sqr(nx ^ 2 + ny ^ 2 + nz ^ 2))
 
ox1 = CSng(ox / Sqr(ox ^ 2 + oy ^ 2 + oz ^ 2))
oy1 = CSng(oy / Sqr(ox ^ 2 + oy ^ 2 + oz ^ 2))
oz1 = CSng(oz / Sqr(ox ^ 2 + oy ^ 2 + oz ^ 2))
 
ax1 = CSng(ax / Sqr(ax ^ 2 + ay ^ 2 + az ^ 2))
ay1 = CSng(ay / Sqr(ax ^ 2 + ay ^ 2 + az ^ 2))
az1 = CSng(az / Sqr(ax ^ 2 + ay ^ 2 + az ^ 2))

If nx1 <> 0 Then
    c = CDbl(Atn(ny1 / nx1) * 180 / pi)
    Else
    c = -90
    End If
    b = CDbl(Atn(-1 * nz1 / (Cos(c * pi / 180) * nx1 + Sin(c * pi / 180) * ny1)) * 180 / pi)
    a = CDbl(Atn((Sin(c * pi / 180) * ax1 - Cos(c * pi / 180) * ay1) / (-1 * Sin(c * pi / 180) * ox1 + Cos(c * pi / 180) * oy1)) * 180 / pi)
 
    Print #1, NN - i; XX; YY; ZZ; a; b; c
    XX = XX + x0
    YY = YY + y0
    ZZ = ZZ + z0
    Print #2, XX; YY; ZZ; a; b; c
    Print #3, NN - i, nx1, ny1, nz1, ox1, oy1, oz1
    Print #3, NN - i, ax1, ay1, az1, XX, YY, ZZ
Close #1
Close #2
Close #3
End Sub
搜索更多相关主题的帖子: Sub Text For Cos Print 
2017-11-28 14:20
快速回复:程序运行时出现错误6“溢出”的提示,请问怎么解决?程序如下:
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.091761 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved