| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 3711 人关注过本帖
标题:EXCEL中VB编程器里程序出现下标越界,错误9,请大家指点那里的问题
只看楼主 加入收藏
aqiang117
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2007-8-15
收藏
 问题点数:0 回复次数:3 
EXCEL中VB编程器里程序出现下标越界,错误9,请大家指点那里的问题

大家好,我是新手,在EXCEL中VBA编了一个程序,但调试时出现下标越界是那里的问题,请大家帮我看看你的指点将使我终身受益,谢谢

Sub 计算成缆外径()
Dim DM As Integer
Dim DN As Integer
Dim M As Integer
Dim N As Integer
Dim a As Integer
Dim r As Integer
Dim b As Integer
Dim D As Integer
Dim Dmax As Integer
Dim Dmin As Integer
int1 = 0
Dim y As Integer

M = Worksheets("sheet159").Cells(159, 21)
N = Worksheets("sheeet159").Cells(159, 22)
Pi = 3.1415926
DM = Worksheets("sheeet159").Cells(159, 14)
DN = Worksheets("sheet159").Cells(159, 16)
Dmax = DM + DM / Sin(Pi / (M + N))
Dmin = DM + DM / Sin(Pi / M)
If N = 0 Then
D = Dmin
End If
Do

int1 = int1 + 1
D = (Dmax + Dmin) / 2
a = (1 - 2 * DM ^ 2 / (D - DM) ^ 2)
r = (1 - 2 * DM * DN / (D - DM) / (D - DN))
b = (1 - 2 * DN ^ 2 / (D - DN) ^ 2)
y = (M - 1) * a + (N - 1) * b + 2 * r
If y < 2 * Pi Then
Dmax = D
Else:
Dmin = D
End If
Loop While y - 2 * Pi < 0.0001


Worksheets("sheeet159").Cells(159, 27) = D

End Sub

搜索更多相关主题的帖子: Integer EXCEL中 Dim 越界 
2007-08-15 11:28
aqiang117
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2007-8-15
收藏
得分:0 

Sub 计算成缆外径()
Dim DM As Single '大截面线芯的直径'
Dim DN As Single '小截面线芯的直径'
Dim M As Integer '大截面线芯的个数'
Dim N As Integer '小截面线芯的个数'
Dim a As Single '大截面线芯之间的夹角'
Dim r As Single '大截面与小截面线芯之间的夹角'
Dim b As Single '小截面线芯之间的夹角'
Dim D As Single '成缆直径'
Dim Dmax As Single
Dim Dmin As Single

Dim y As Single

M = Worksheets("sheet159").Cells(159, 21)
N = Worksheets("sheeet159").Cells(159, 22)
Pi = 3.1415926
DM = Worksheets("sheeet159").Cells(159, 14)
DN = Worksheets("sheet159").Cells(159, 16)
Dmax = DM + DM / Sin(Pi / (M + N))
Dmin = DM + DM / Sin(Pi / M)
If N = 0 Then
D = Dmin
End If
Do

int1 = int1 + 1
D = (Dmax + Dmin) / 2
a = (1 - 2 * DM ^ 2 / (D - DM) ^ 2)
r = (1 - 2 * DM * DN / (D - DM) / (D - DN))
b = (1 - 2 * DN ^ 2 / (D - DN) ^ 2)
y = (M - 1) * a + (N - 1) * b + 2 * r
If y < 2 * Pi Then
Dmax = D
Else:
Dmin = D
End If
Loop While y - 2 * Pi < 0.0001


Worksheets("sheeet159").Cells(159, 27) = D

End Sub

我把程序重新修改了一下,逐语句运行
Sub 计算成缆外径()在此出错
M = Worksheets("sheet159").Cells(159, 21)
在此出错
N = Worksheets("sheeet159").Cells(159, 22)
在此出错
接下来调试就是下标越界

2007-08-15 12:16
multiple1902
Rank: 8Rank: 8
等 级:贵宾
威 望:42
帖 子:4881
专家分:671
注 册:2007-2-9
收藏
得分:0 
Worksheets("sheet159").Cells(159, 21)
你确定有这个细胞吗?
2007-08-15 12:20
aqiang117
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2007-8-15
收藏
得分:0 
谢谢版主提醒,我再次分析一下M = Worksheets("sheet159").Cells(159, 21)这个可以从EXCEL向程序中读数值的语句是否有问题
2007-08-15 14:35
快速回复:EXCEL中VB编程器里程序出现下标越界,错误9,请大家指点那里的问题
数据加载中...
 
   



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

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