| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1567 人关注过本帖
标题:vb的红绿灯问题
只看楼主 加入收藏
ggggiaqgyd
Rank: 1
等 级:新手上路
帖 子:49
专家分:0
注 册:2007-10-13
收藏
 问题点数:0 回复次数:6 
vb的红绿灯问题
就是用一个或几个时间控件,还有三个图片,通过设置他们的visble的值来控制红绿灯的实现.我以前以为很简单,自己做了发现,很难
请大家帮帮忙
Private Sub Timer1_Timer()
Picture1.Visible = True
Picture2.Visible = False
Picture2.Visible = False
a = a + 1
Label1.Caption = a
If a = 5 Then
Timer1.Enabled = False
Timer2.Enabled = True
Timer3.Enabled = False
End If
End Sub

Private Sub Timer2_Timer()
Picture1.Visible = False
Picture2.Visible = True
Picture2.Visible = False
b = b + 1
Label1.Caption = b
If b = 3 Then
Timer1.Enabled = False
Timer2.Enabled = False
Timer3.Enabled = True
End If
End Sub

Private Sub Timer3_Timer()
Picture1.Visible = True
Picture2.Visible = False
Picture2.Visible = False
c = c + 1
Label1.Caption = c
If c = 5 Then
Timer1.Enabled = True
Timer2.Enabled = False
Timer3.Enabled = False
End If
End Sub
搜索更多相关主题的帖子: 红绿灯 
2008-10-12 15:47
multiple1902
Rank: 8Rank: 8
等 级:贵宾
威 望:42
帖 子:4881
专家分:671
注 册:2007-2-9
收藏
得分:0 
a = a + 1

a在哪里定义了?
2008-10-12 15:58
kgdwgija
Rank: 1
等 级:新手上路
帖 子:22
专家分:0
注 册:2008-9-25
收藏
得分:0 
Dim a As Integer
Dim b As Integer
Dim c As Integer
通用,声明变量

Private Sub Timer1_Timer()
Picture1.Visible = True
Picture2.Visible = False
Picture3.Visible = False
a = 0
a = a + 1
Label1.Caption = a
If a = 1 Then

Timer1.Enabled = False
Timer2.Enabled = True
Timer3.Enabled = False
End If
End Sub

Private Sub Timer2_Timer()
Picture1.Visible = False
Picture2.Visible = True
Picture3.Visible = False
b = 1
b = b + 1
Label2.Caption = b
If b = 2 Then

Timer1.Enabled = False
Timer2.Enabled = False
Timer3.Enabled = True
End If
End Sub

Private Sub Timer3_Timer()
Picture1.Visible = False
Picture2.Visible = False
Picture3.Visible = True
c = 2
c = c + 1
Label3.Caption = c
If c = 3 Then
Timer1.Enabled = True
Timer2.Enabled = False
Timer3.Enabled = False
End If
End Sub

三个TIME的时间先别为
1:600
2:800
3:850


你就可以转了。
我用了三个LABEL 呵。
如有不对的地方请指出。。。谢谢。
2008-10-12 17:01
风吹过b
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:贵宾
威 望:364
帖 子:4943
专家分:30067
注 册:2008-10-15
收藏
得分:0 
我用3个shape控件+1个time控件做的,源码如下:

Option Explicit

'被注释掉的代码是用于一个 shape1 控件的
'用3个 shape1 控件时,用现在的

Dim wtime(3) As Long            '3个灯变换之间的时间,以秒为单位
Dim color(3) As Long             '3个灯的颜色


Private Sub Form_Load()
'3个灯的时间
wtime(1) = 10
wtime(2) = 20
wtime(3) = 3

'3个灯的颜色,这里用 shape 来显示灯
color(1) = RGB(255, 0, 0)
color(2) = RGB(0, 255, 0)
color(3) = RGB(255, 255, 0)

With Shape1
    .FillStyle = 0
    .Shape = 3
    .FillColor = color(1)
End With

'以下代码是基于 3个 shape 的后面二个,如果用一个,全部注释掉
With Shape2
    .FillStyle = 0
    .Shape = 3
    .FillColor = color(2)
    .Visible = False
End With

With Shape3
    .FillStyle = 0
    .Shape = 3
    .FillColor = color(3)
    .Visible = False
End With

End Sub

Private Sub Timer1_Timer()
Static jc As Long       '计次用的
Static js As Long       '计数用的

If jc < 1 Then jc = 0   '确保jc最小为1
If jc > 3 Then jc = 3   '确保jc最大为3

js = js + 1             '计秒+1,如果要显示,到这后面处理,
        
If js > wtime(jc) Then      '满了秒
    jc = jc + 1             '计次+1
    js = 0                  '秒回 0
    If jc > 3 Then jc = 1   '大于3,返回到 1
   
    '下面一行是用一个 shape 的
'    Shape1.FillColor = color(jc)

    '下面这个多分支是用于3个 shape 的
    Select Case jc
        Case 1
            Shape1.Visible = True
            Shape2.Visible = False
            Shape3.Visible = False
        Case 2
            Shape1.Visible = False
            Shape2.Visible = True
            Shape3.Visible = False
        Case 3
            Shape1.Visible = False
            Shape2.Visible = False
            Shape3.Visible = True
    End Select
End If
End Sub
2008-10-15 23:39
我一定要坚持
Rank: 1
来 自:西方大雷音
等 级:新手上路
威 望:1
帖 子:159
专家分:0
注 册:2008-10-7
收藏
得分:0 
这个用单片机来做就比较简单了,我以前在学校的时候做过,不过用的程序行数要多一点,其实只需要做一路的就可以了,然后把控制信号线反过来接到另一路去就行了,一个十字路听红绿灯控制程序就搞定啦.....
2008-10-16 01:31
快速回复:vb的红绿灯问题
数据加载中...
 
   



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

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