实际工程中用到定时器数组控件,问题简化如下:现有定时器数组控件Timer1(0).Timer, Timer1(1).Timer......Timer1(5).Timer, 用for循环给每个数组成员interval赋值后,定时器的事件是什么呢?我用Private Sub Timer1_Timer(index As Integer),发现所有的定时器都是按时间值最小的那个来动作。通道事件也用一个for循环,应该怎么写?
解决方案 »
- 组合数问题
- Excel 2007 下无法录制宏
- 向大家推荐一套VB换肤软件Skin++ 3.0 For VB
- 用EnumChildWindows(api),如何得到form下的textbox的句柄?
- MaskEdBox赋值及取值
- 如何將一個數據庫的所有表結構轉入文本文件或是其他的文件?
- Bardo(巴顿)进来领分,详见http://www.csdn.net/expert/topic/544/544069.xml
- 菜鸟的 SQL 问题,想要分快来!!!!
- 急!在HTML Help Workshop中怎样使.htm文件跟控件联系起来???
- 用vba,打开我的电脑d盘wdxx文件夹下面叫hi555的Excel,并复制sheet名字叫aa的那张sheet,新手,谢谢了
- 如何读取数码照片的EXIF,并把时间和日期写到照片上
- VB运行环境的问题
Dim i As Byte
For i = 0 To Timer1.Count - 1
Timer1(i).Interval = 1000 + 1000 * i
Next
End SubPrivate Sub Timer1_Timer(Index As Integer)
Debug.Print "timer" & Index
End Sub需求不明确,看看这个效果
Dim a(5), b(5), c(5), x(5), y(5) As Integer
Private Sub Command1_Click() For n = 0 To 5
Timer2(n).Interval = y(n)
Timer2(n).Enabled = True
Next n
End SubPrivate Sub Command2_Click() For n = 0 To 5
Text1(n).Text = 0
Text2(n).Text = 0
Text3(n).Text = 0
Next n
End SubPrivate Sub Form_Load()
Timer1.Interval = 50
For n = 0 To 5
Text1(n).Text = 0
Text2(n).Text = 0
Text3(n).Text = 0
Next n
End SubPrivate Sub Timer1_Timer() For k = 0 To 5
a(k) = Val(Text1(k).Text)
b(k) = Val(Text2(k).Text)
c(k) = Val(Text3(k).Text)
x(k) = Abs((b(k) - a(k)) / 0.1)
If x(k) = 0 Then
y(k) = 0
Else
y(k) = c(k) * 1000 / x(k)
End If
Next k
End SubPrivate Sub Timer2_Timer(Index As Integer) For m = 0 To 5
If b(m) > a(m) Then
a(m) = a(m) + 0.1
Else
If b(m) < a(m) Then
a(m) = a(m) - 0.1
Else
If a(m) = b(m) Then
Timer2(m).Enabled = False
End If
End If
End If
Text1(m).Text = a(m)
Next m
End Sub
请各位朋友指教。
select case index
case 0
'timer1(0)的事件
case 1
'timer1(1)的事件
case 2
'timer1(2)的事件
case 3
'timer1(3)的事件
end select
'
' For m = 0 To 5
' If b(m) > a(m) Then
' a(m) = a(m) + 0.1
' Else
' If b(m) < a(m) Then
' a(m) = a(m) - 0.1
' Else
' If a(m) = b(m) Then
' Timer2(m).Enabled = False
'
' End If
' End If
' End If
'
' Text1(m).Text = a(m)
' Next m a(Index) = a(Index) + 0.1
If b(Index) = a(Index) Then Timer2(Index).Enabled = False
Text1(Index) = a(Index)
End Sub
要考虑timer的延时不很准确,最低大约20ms+-5ms
select case index
case 0
'timer1(0)的事件
case 1
'timer1(1)的事件
case 2
'timer1(2)的事件
case 3
'timer1(3)的事件
end select
用7楼朋友的方法,问题解决。结帖,散分!