| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1906 人关注过本帖
标题:VB下标越界
只看楼主 加入收藏
梦昔梦矣
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2018-4-16
结帖率:100%
收藏
 问题点数:0 回复次数:2 
VB下标越界
各位大佬,我运行为什么下面程序会出现下标越界,跪求答案
Private Sub Command1_Click()
Dim a!, b!, c!
Dim i(1 To 6)  As Single
Dim l(1 To 6)  As Single
Dim h(1 To 6)  As Single
Dim pd(1 To 6) As Single
Dim pc(1 To 6) As Single
Dim bg(1 To 6) As Single
For a = 1 To 6
   i(a) = Val(InputBox("输入第" & a & "段线路坡度"))
   l(a) = Val(InputBox("输入第" & a & "段线路长度"))
   h(a) = Val(InputBox("输入第" & a & "段线路标高"))
Next a
c = 1
b = 1

Do While c < 7

      pd(b) = (h(c + 1) - h(c)) * 1000 / (l(c) + l(c + 1))
   
   If l(c) * Abs(pd(b) - i(c)) <= 2000 And l(c + 1) * Abs(pd(b) - i(c + 1)) <= 2000 Then
 
        pd(b + 1) = (h(c + 2) - h(c)) * 1000 / (l(c) + l(c + 1) + l(c + 2))
   
      If Abs(pd(b + 1) - i(c)) * l(c) <= 2000 And Abs(pd(b + 1) - i(c + 2)) * l(c + 2) <= 2000 And Abs(pd(b + 1) - i(c + 1)) * l(c + 1) <= 2000 Then
   
         
         Label1.Caption = Label1.Caption & pd(b + 1) & vbCrLf
      
         Label2.Caption = Label2.Caption & (l(c) + l(c + 1) + l(c + 2)) & vbCrLf
         
         c = c + 3
         
         b = b + 1
      Else
         Label1.Caption = Label1.Caption & pd(b) & vbCrLf
      
        Label2.Caption = Label2.Caption & (l(c) + l(c + 1)) & vbCrLf
         
         c = c + 2
         
         b = b + 1
       End If
   Else
   
       Label1.Caption = Label1.Caption & i(c) & vbCrLf
      
        Label2.Caption = Label2.Caption & l(c) & vbCrLf
        
         c = c + 1
         
         b = b + 1
   End If
  
Loop

End Sub
搜索更多相关主题的帖子: 越界 Dim Single Abs Caption 
2018-04-19 23:09
HVB6
Rank: 7Rank: 7Rank: 7
等 级:贵宾
威 望:15
帖 子:331
专家分:561
注 册:2013-10-30
收藏
得分:0 
回复 楼主 梦昔梦矣
Private Sub Command1_Click()
Dim a!, b!, c!
Dim i(1 To 6)  As Single
Dim l(1 To 6)  As Single
Dim h(1 To 6)  As Single
Dim pd(1 To 6) As Single
Dim pc(1 To 6) As Single
Dim bg(1 To 6) As Single
For a = 1 To 6
   i(a) = Val(InputBox("输入第" & a & "段线路坡度"))
   l(a) = Val(InputBox("输入第" & a & "段线路长度"))
   h(a) = Val(InputBox("输入第" & a & "段线路标高"))
Next a
c = 1
b = 1
Do While c < 7
      pd(b) = (h(c + 1) - h(c)) * 1000 / (l(c) + l(c + 1))
当c=6时,h(c + 1) 和l(c + 1)超标,后面的代码有可能亦如此。
2018-04-20 07:40
梦昔梦矣
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2018-4-16
收藏
得分:0 
非常感谢!!!
2018-04-20 15:51
快速回复:VB下标越界
数据加载中...
 
   



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

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