关于错误6溢出

夏至oyy 2013-10-29 03:33:01
最近遇到一个问题,求帮组。表达能力有限,谅解。
在完成的软件中添加一个功能,当设备不在线时,调用以前写好的重连函数。每五秒重连一次。
主要代码如下:
(Picture16_DblClick(1)这个函数在以前就实现,运行一直没有问题的)

 Dim one_Time_Count As Long  '自动重连计时器
Dim two_Time_Count As Long '自动重连计时器
Dim three_Time_Count As Long '自动重连计时器
Private Sub Timer1_Timer()
one_Time_Count = one_Time_Count + 1
two_Time_Count = two_Time_Count + 1
three_Time_Count = three_Time_Count + 1
end sub
Private Sub Timer2_Timer()‘重连的调用
On Error Resume Next
If Picture16(1).Visible = True Then
If one_Time_Count >= 5 Then
Call Picture16_DblClick(1)
one_Time_Count = 0
End If
End If
If Picture16(2).Visible = True Then
If two_Time_Count >= 5 Then
Call Picture16_DblClick(2)
two_Time_Count = 0
End If
End If
If Picture16(3).Visible = True Then
If three_Time_Count >= 5 Then
Call Picture16_DblClick(3)
three_Time_Count = 0
End If
End If
End Sub

在我加了这段代码后,程序运行一天后,会报错,错误6,溢出。
我在WIN7下运行没有问题,客户电脑用的是XP英文版。在客户电脑上的VB有点问题,用VB建立一个空的工程会报错下标越界。
我想解决程序在客户电脑上报溢出的错误。求指导~~~。是代码的问题还是环境的问题?或者其他。
...全文
136 8 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
of123 2013-10-30
  • 打赏
  • 举报
回复
 
Dim Time_Count(1 To 3) As Long  '自动重连计时器
Dim i As Integer
Private Sub Timer1_Timer()
    For i = 1 To 3
        If Time_Count(i) < 5 Then Time_Count(i) = Time_Count(i) + 1

        If Picture16(i).Visible And Time_Count(i) = 5 Then
            Call Picture16_DblClick(i)
            Time_Count(i) = 0
        End If
    Next i
End Sub
1 计数器不要不停地加。因为你的清零代码是有条件的,条件长时间不满足时计数器会溢出。 2 如果 Picture16_DblClick 不是占用时间很长,就不需要 2 个定时器。
夏至oyy 2013-10-30
  • 打赏
  • 举报
回复
引用 7 楼 of123 的回复:
 
Dim Time_Count(1 To 3) As Long  '自动重连计时器
Dim i As Integer
Private Sub Timer1_Timer()
    For i = 1 To 3
        If Time_Count(i) < 5 Then Time_Count(i) = Time_Count(i) + 1

        If Picture16(i).Visible And Time_Count(i) = 5 Then
            Call Picture16_DblClick(i)
            Time_Count(i) = 0
        End If
    Next i
End Sub
1 计数器不要不停地加。因为你的清零代码是有条件的,条件长时间不满足时计数器会溢出。 2 如果 Picture16_DblClick 不是占用时间很长,就不需要 2 个定时器。
嗯。受教。
worldy 2013-10-29
  • 打赏
  • 举报
回复
你不是要运行一天才会报错吗?等呗
夏至oyy 2013-10-29
  • 打赏
  • 举报
回复
引用 4 楼 worldy 的回复:
[quote=引用 3 楼 jamesczy 的回复:] [quote=引用 1 楼 worldy 的回复:] Private Sub Timer2_Timer()‘重连的调用 On Error Resume Next'z这是掩盖错误做法,程序有问题就没法知道,正确的是[/color] On Error Goto ErrHandler If Picture16(1).Visible = True Then If one_Time_Count >= 5 Then Call Picture16_DblClick(1) one_Time_Count = 0 End If End If If Picture16(2).Visible = True Then If two_Time_Count >= 5 Then Call Picture16_DblClick(2) two_Time_Count = 0 End If End If If Picture16(3).Visible = True Then If three_Time_Count >= 5 Then Call Picture16_DblClick(3) three_Time_Count = 0 End If End If exit sub‘好像我的代码里面没有这句。在时钟函数中加上这句和不加的区别是什么? ErrHandler: msgbox err.description''让程序报告错误 End Sub
exit sub‘好像我的代码里面没有这句。在时钟函数中加上这句和不加的区别是什么? [/quote] 我帮你加的,用于在不出错的时候,不让程序显示错误对话框[/quote] 加了,程序运行没有问题。没有报错。
worldy 2013-10-29
  • 打赏
  • 举报
回复
引用 3 楼 jamesczy 的回复:
[quote=引用 1 楼 worldy 的回复:] Private Sub Timer2_Timer()‘重连的调用 On Error Resume Next'z这是掩盖错误做法,程序有问题就没法知道,正确的是[/color] On Error Goto ErrHandler If Picture16(1).Visible = True Then If one_Time_Count >= 5 Then Call Picture16_DblClick(1) one_Time_Count = 0 End If End If If Picture16(2).Visible = True Then If two_Time_Count >= 5 Then Call Picture16_DblClick(2) two_Time_Count = 0 End If End If If Picture16(3).Visible = True Then If three_Time_Count >= 5 Then Call Picture16_DblClick(3) three_Time_Count = 0 End If End If exit sub‘好像我的代码里面没有这句。在时钟函数中加上这句和不加的区别是什么? ErrHandler: msgbox err.description''让程序报告错误 End Sub
exit sub‘好像我的代码里面没有这句。在时钟函数中加上这句和不加的区别是什么? [/quote] 我帮你加的,用于在不出错的时候,不让程序显示错误对话框
夏至oyy 2013-10-29
  • 打赏
  • 举报
回复
引用 1 楼 worldy 的回复:
Private Sub Timer2_Timer()‘重连的调用 On Error Resume Next'z这是掩盖错误做法,程序有问题就没法知道,正确的是[/color] On Error Goto ErrHandler If Picture16(1).Visible = True Then If one_Time_Count >= 5 Then Call Picture16_DblClick(1) one_Time_Count = 0 End If End If If Picture16(2).Visible = True Then If two_Time_Count >= 5 Then Call Picture16_DblClick(2) two_Time_Count = 0 End If End If If Picture16(3).Visible = True Then If three_Time_Count >= 5 Then Call Picture16_DblClick(3) three_Time_Count = 0 End If End If exit sub‘好像我的代码里面没有这句。在时钟函数中加上这句和不加的区别是什么? ErrHandler: msgbox err.description''让程序报告错误 End Sub
exit sub‘好像我的代码里面没有这句。在时钟函数中加上这句和不加的区别是什么?
夏至oyy 2013-10-29
  • 打赏
  • 举报
回复
按照你的意思该了,程序没有报错。 主要的问题是,程序是在运行了一段时间后报错。
worldy 2013-10-29
  • 打赏
  • 举报
回复
Private Sub Timer2_Timer()‘重连的调用 ' On Error Resume Next'z这是掩盖错误做法,程序有问题就没法知道,正确的是 On Error Goto ErrHandler If Picture16(1).Visible = True Then If one_Time_Count >= 5 Then Call Picture16_DblClick(1) one_Time_Count = 0 End If End If If Picture16(2).Visible = True Then If two_Time_Count >= 5 Then Call Picture16_DblClick(2) two_Time_Count = 0 End If End If If Picture16(3).Visible = True Then If three_Time_Count >= 5 Then Call Picture16_DblClick(3) three_Time_Count = 0 End If End If exit sub ErrHandler: msgbox err.description''让程序报告错误 End Sub

7,785

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧