我的意思是,比如说先让LED1亮,后LED4亮,后LED11亮,……。它们的编号先后没有规律,怎么用TIMER啊? 又不能这样: Private Sub timerAutoDO_Timer() ledDO(m_DOLedcurrIndex).Value = 1 Call ZT8403_DOBit(m_cardNO, m_DOLedcurrIndex + 1, 1) m_DOLedcurrIndex = m_DOLedcurrIndex + 1 End Sub
Option Explicit Dim i As Integer Dim sum As Integer Private Sub Form_Load() For i = 0 To 5 Shape1(i).Visible = False Image1(i).Visible = False Next End SubPrivate Sub Timer1_Timer() Randomize For i = 0 To 5 Shape1(i).Visible = False Image1(i).Visible = False Next sum = Int((6 * Rnd) + 1) - 1 Text1 = sum Shape1(sum).Visible = True Image1(sum).Visible = True End Sub
我试着编了一个,但是不对,问题不是一点点。我是菜鸟,我是为了毕业设计刚学的VB。帮我看看Option ExplicitPrivate Sub Form_Load() Dim arrLight(1 To 3) As Integer arrLight(1) = 2: arrLight(2) = 8: arrLight(3) = 9 End SubPrivate Sub Timer1_Timer() Dim i As Integer i = 1 Led1(arrLight(i)).Value = 1 i = i + 1 End Sub
Private Sub Timer1_Timer() Dim i As Integer i = 1 Led1(arrLight(i)).Value = 1 i = i + 1 End Sub什么语言这样定义的变量也是局部变量阿,怎么着你也static一下吧Option Explicit dim i as integerPrivate Sub Form_Load() Dim arrLight(1 To 3) As Integer arrLight(1) = 2: arrLight(2) = 8: arrLight(3) = 9 End SubPrivate Sub Timer1_Timer() if i=3 then i=1 Led1(arrLight(i)).Value = 1 i = i + 1 End Sub
不对啊,编译错误:子程序或函数未定义 光标在倒数第三行的"arrLight"上.
经修改: Option ExplicitDim arrLight(1 To 3) As Integer Dim i As IntegerPrivate Sub Form_Load()arrLight(1) = 2: arrLight(2) = 7: arrLight(3) = 8 End SubPrivate Sub Timer1_Timer() If i = 3 Then i = 1 Led1(arrLight(i)).Value = 1 i = i + 1 End Sub结果倒数第三行黄色高亮,"下标越界",什么意思啊?
经修改: Option ExplicitDim arrLight(0 To 2) As Integer Dim i As IntegerPrivate Sub Form_Load()arrLight(0) = 2: arrLight(1) = 3: arrLight(2) = 8 End SubPrivate Sub Timer1_Timer() If i = 3 Then i = 0 Led1(arrLight(i)).Value = 1 i = i + 1 End Sub 搞定了,谢谢各位,特别是clear_zero!
如果图片显示要与LED显示有关系的话,就必须知道
LED的状态(包括获取它的ID,是否亮等)。
又不能这样:
Private Sub timerAutoDO_Timer()
ledDO(m_DOLedcurrIndex).Value = 1
Call ZT8403_DOBit(m_cardNO, m_DOLedcurrIndex + 1, 1)
m_DOLedcurrIndex = m_DOLedcurrIndex + 1
End Sub
Dim i As Integer
Dim sum As Integer
Private Sub Form_Load()
For i = 0 To 5
Shape1(i).Visible = False
Image1(i).Visible = False
Next
End SubPrivate Sub Timer1_Timer()
Randomize
For i = 0 To 5
Shape1(i).Visible = False
Image1(i).Visible = False
Next
sum = Int((6 * Rnd) + 1) - 1
Text1 = sum
Shape1(sum).Visible = True
Image1(sum).Visible = True
End Sub
我的课程设计题目是轨道交通沿路信号采集与展示控制的软件设计。软件界面是32个LED显示32路采集卡的通道的状况,我要做的是点击软件上代表某线轨道(比如一号线)的起点站的LED,接着代表这一路的站点的LED一个接一个的亮起来,比如是(LED(1)、LED(3)、LED(14)、LED(23))这不是随机的,假设一号线就这么几个固定站点的灯。
要一个接一个亮起来我想是要TIMER的,但这几个编号之间是没有规律的,不能每执行一个TIMER的周期编号加一加二这样解决,我不知道该怎样编程,解决了我就散分,谢谢!
你做这样一个函数,然后把所有一号线上的灯的id存在一个数组里面,比如叫arrLight,然后启动timer在timer中按顺序亮arrLight里面的led就好了
Dim arrLight(1 To 3) As Integer
arrLight(1) = 2: arrLight(2) = 8: arrLight(3) = 9
End SubPrivate Sub Timer1_Timer()
Dim i As Integer
i = 1
Led1(arrLight(i)).Value = 1
i = i + 1
End Sub
Dim i As Integer
i = 1
Led1(arrLight(i)).Value = 1
i = i + 1
End Sub什么语言这样定义的变量也是局部变量阿,怎么着你也static一下吧Option Explicit
dim i as integerPrivate Sub Form_Load()
Dim arrLight(1 To 3) As Integer
arrLight(1) = 2: arrLight(2) = 8: arrLight(3) = 9
End SubPrivate Sub Timer1_Timer()
if i=3 then i=1
Led1(arrLight(i)).Value = 1
i = i + 1
End Sub
光标在倒数第三行的"arrLight"上.
Option ExplicitDim arrLight(1 To 3) As Integer
Dim i As IntegerPrivate Sub Form_Load()arrLight(1) = 2: arrLight(2) = 7: arrLight(3) = 8
End SubPrivate Sub Timer1_Timer()
If i = 3 Then i = 1
Led1(arrLight(i)).Value = 1
i = i + 1
End Sub结果倒数第三行黄色高亮,"下标越界",什么意思啊?
第一。我想你32个LED表示了某城市的轨道交通站点,假如有三条轨道交通线:
1号线15站点
2号线9站点
3号线8站点
你应做3个数组控件,分别由Timer控件来操纵,那就不会存在你的问题。
第二。你的课程设计题目还应涉及沿路信号数据采集和与PC机的通信,这牵涉到通信数据协议及相应的软硬件。
第三。软件应有图形界面,便于直观显示各轨道交通线路和实际状况。
Option ExplicitDim arrLight(0 To 2) As Integer
Dim i As IntegerPrivate Sub Form_Load()arrLight(0) = 2: arrLight(1) = 3: arrLight(2) = 8
End SubPrivate Sub Timer1_Timer()
If i = 3 Then i = 0
Led1(arrLight(i)).Value = 1
i = i + 1
End Sub
搞定了,谢谢各位,特别是clear_zero!