VB中提示实时错误下标越界9什么问题啊!我是新手
Private Sub MSComm1_OnComm()
Static maxv '存储最大幅度值
ReDim Preserve f(n) '存储频率值
ReDim Preserve v(n) '存储幅度值
ReDim Preserve changef(n2) '存储共振频率变化值
ReDim Preserve yyy2(n2) '画曲线时保修上一次的纵坐标
ReDim Preserve yyy3(n2)
ReDim Preserve ampmax(n2) '用于保存幅度峰值
ReDim Preserve tim(n2) '用于记录共振频率时的时间
Dim j As Integer
Dim k As Integer
ReDim BeforeFilter(n + 1)
ReDim AfterFilter(n + 1)
sindata = MSComm1.Input '读入输入缓冲区数据
indata = Val(sindata(0)) '将接收到的二进制数转换成十进制数
v(ii) = indata
'v(ii) = (indata / 255) * 5 '幅度值
ii = ii + 1
ProgressBar1.Max = n + 1 '进度显示
ProgressBar1.Value = ii
If ii = n + 1 Then '判断步进次数是否已到
ProgressBar1.Visible = False '关闭测量进度条
maxv0 = 0
' For j = 2 To n - 2
' If (v(j) - v(j - 1) >= 0) Or (v(j - 1) - v(j - 2) >= 0) Or (v(j) - v(j + 1) >= 0) Or (v(j + 1) - v(j + 2) <= 0) Or _
' (v(j) - v(j - 1) >= 0) Or (v(j - 1) - v(j - 2) <= 0) Or (v(j) - v(j + 1) >= 0) Or (v(j + 1) - v(j + 2) >= 0) Then
' v(j) = (v(j - 1) + v(j + 1)) / 2
' End If
' Next j
For j = 2 To n - 2
If ((v(j) - v(j - 1) >= 0) And (v(j - 1) - v(j - 2) >= 0) And (v(j) - v(j + 1) >= 0) And (v(j + 1) - v(j + 2) <= 0)) Or _
((v(j) - v(j - 1) >= 0) And (v(j - 1) - v(j - 2) <= 0) And (v(j) - v(j + 1) >= 0) And (v(j + 1) - v(j + 2) <= 0)) Or _
((v(j) - v(j - 1) >= 0) And (v(j - 1) - v(j - 2) <= 0) And (v(j) - v(j + 1) >= 0) And (v(j + 1) - v(j + 2) >= 0)) Then
v(j) = (v(j - 1) + v(j + 1)) / 2
End If
Next j
'
For j = 2 To n - 2
If ((v(j) - v(j - 1) <= 0) And (v(j - 1) - v(j - 2) >= 0) And (v(j) - v(j + 1) <= 0) And (v(j + 1) - v(j + 2) <= 0)) Or _
((v(j) - v(j - 1) <= 0) And (v(j - 1) - v(j - 2) <= 0) And (v(j) - v(j + 1) <= 0) And (v(j + 1) - v(j + 2) <= 0)) Or _
((v(j) - v(j - 1) <= 0) And (v(j - 1) - v(j - 2) <= 0) And (v(j) - v(j + 1) <= 0) And (v(j + 1) - v(j + 2) >= 0)) Then
v(j) = (v(j - 1) + v(j + 1)) / 2
End If
Next j
' For j = 2 To n - 2
' If ((v(j) - v(j - 1) <= 0) And (v(j - 1) - v(j - 2) >= 0) And (v(j) - v(j + 1) <= 0) And (v(j + 1) - v(j + 2) <= 0)) Or _
' ((v(j) - v(j - 1) <= 0) And (v(j - 1) - v(j - 2) <= 0) And (v(j) - v(j + 1) <= 0) And (v(j + 1) - v(j + 2) >= 0)) Then
' v(j) = (v(j - 1) + v(j + 1)) / 2
' End If
' Next j
For j = 0 To n
BeforeFilter(j) = v(j)
Next j
Call Filter(BeforeFilter(), n + 1)
For j = 0 To n
v(j) = AfterFilter(j)
Next j
For k = 1 To n
f(k) = f0 + k * ff / 1000
indata2 = v(k)
'yy1 = (indata2 / 5) * Picture1.Height '根据接收的数据计算y坐标值
yy1 = (indata2 / 255) * Picture1.Height '根据接收的数据计算y坐标值
xx1 = (k / n) * Picture1.Width '计算x坐标值
Picture1.DrawWidth = 2
Picture1.Line -(xx1, yy1), QBColor(13) '画曲线
If maxv0 < v(k) Then
maxv0 = v(k)
maxv = maxv0 / 51
'maxv = maxv0
Text1.Text = f(k)
Text7.Text = maxv
coun2 = coun1
End If
MaxFreq = MaxFreq + ff / 1000
Next k
ii = 0
'maxv = 0 '重置最大幅度值
Timer2.Enabled = False '测量结束,关闭计时器
End If
MSComm1.Output = "b" '发送一个接收应答信号
If ii = 0 Then
If Check1.Value = 1 And jj <= n2 Then
Timer1.Enabled = True '如果是多点测量,则打开计时器
MSComm1.PortOpen = False '关闭串口
ampmax(jj) = CCur(Text7.Text) '保存幅度峰值
xx20 = (jj / n2) * Picture2.Width '求出横坐标值
xx21 = ((jj - 1) / n2) * Picture2.Width '求出上一点的横坐标值
yy2 = (Val(Text1.Text) - Val(Label31.Caption)) * Picture2.Height / (Val(Label36.Caption) - Val(Label31.Caption)) '求出纵坐标值
yyy2(jj) = yy2 '保存此次纵坐标值以便下次画曲线时从此点开始
Picture2.DrawWidth = 2
If jj = 0 Then
Picture2.Line -(xx20, yy2), QBColor(12) '画共振频率变化曲线
Else
Picture2.Line (xx21, yyy2(jj - 1))-(xx20, yy2), QBColor(12) '画共振频率变化曲线
End If
yy3 = Val(Text7.Text) * Picture2.Height / 5 '计算幅度峰值曲线纵坐标
yyy3(jj) = yy3
If jj = 0 Then
Picture2.Line (0, 0)-(xx20, yy3), QBColor(1) '画幅度峰值曲线
Else
Picture2.Line (xx21, yyy3(jj - 1))-(xx20, yy3), QBColor(1) '画幅度峰值曲线
End If
If jj = 0 Then
' tim(jj) = coun2 / 10
tim(jj) = 0
coun3 = coun1 - coun2 '计算每一个共振频率点所对应的时间
coun1 = 0
Else
' tim(jj) = tim(jj - 1) + coun3 / 10 + Val(Text6.Text) + coun2 / 10
tim(jj) = Val(Text6.Text) * jj
coun3 = coun1 - coun2
coun1 = 0
End If
changef(jj) = Text1.Text '存储共振频率变化值
jj = jj + 1
If jj = n2 + 1 Then
jj = 0
End If
End If
End If
If (ii = 0 And Check1.Value = 0) Or (Check1.Value = 1 And ii = 0 And jj = 0) Then '判断测量是否结束
If Not MSComm1.PortOpen = False Then '关闭串口
MSComm1.PortOpen = False
End If
Timer1.Enabled = False '关闭计时器
Text2.Enabled = True '测量结束参数设置框有效
Text3.Enabled = True
Text4.Enabled = True
Text5.Enabled = True
Text6.Enabled = True
Text8.Enabled = True
Text9.Enabled = True
Combo1.Enabled = True
Check1.Enabled = True
Command1.Enabled = False '终止按键不可用
Start1.Enabled = True '开始按键可用
Close1.Enabled = True '退出按键可用
Save1.Enabled = True '保存按键可用
Save2.Enabled = True
End If
End Sub
在别人的电脑上运行就没有问题
[解决办法]
Private Sub MSComm1_OnComm()
Static maxv '存储最大幅度值
ReDim Preserve f(n) '存储频率值
ReDim Preserve v(n) '存储幅度值
ReDim Preserve changef(n2) '存储共振频率变化值
ReDim Preserve yyy2(n2) '画曲线时保修上一次的纵坐标
ReDim Preserve yyy3(n2)
ReDim Preserve ampmax(n2) '用于保存幅度峰值
ReDim Preserve tim(n2) '用于记录共振频率时的时间
Dim j As Integer
Dim k As Integer
ReDim BeforeFilter(n + 1)
ReDim AfterFilter(n + 1)
sindata = MSComm1.Input '读入输入缓冲区数据
indata = Val(sindata(0)) '将接收到的二进制数转换成十进制数
[解决办法]
在别人那没问题,可能就说明你们数据不一样,数据不一样,数组就不一样,数组不一样,所以就越界了- -这长呢- -
[解决办法]
错在哪一行?
[解决办法]
indata = Val(sindata(0)) '将接收到的二进制数转换成十进制数
[解决办法]
在别人的电脑上用同样的可执行文件,测同样的东西就是好的
但我的就不行
[解决办法]
你断点debug下就知道了