问答文章1 问答文章501 问答文章1001 问答文章1501 问答文章2001 问答文章2501 问答文章3001 问答文章3501 问答文章4001 问答文章4501 问答文章5001 问答文章5501 问答文章6001 问答文章6501 问答文章7001 问答文章7501 问答文章8001 问答文章8501 问答文章9001 问答文章9501

vb写一个简单红绿灯程序代码,希望能注释和思路写清楚一点,我菜鸟!谢谢

发布网友 发布时间:2022-04-29 09:32

我来回答

3个回答

热心网友 时间:2023-10-13 22:25

'ZT是当前状态记录,Qzt是前状态记录,SJ是时间记录
Dim ZT As Integer, Qzt As Integer, Sj As Integer
Private Sub Command1_Click()
If Command1.Caption = "开始" Then
Command1.Caption = "20停止"
Timer1.Enabled = True
Shape3.FillColor = &HFF&
ZT = 3
Qzt = 3
Else
Command1.Caption = "开始"
Timer1.Enabled = False
Shape1.FillColor = &H4000&
Shape2.FillColor = &H8080&
Shape3.FillColor = &H40&
ZT = 0
End If

End Sub

Private Sub Form_Load()
Shape1.FillStyle = 0 '绿灯
Shape2.FillStyle = 0 '黄灯
Shape3.FillStyle = 0 '红灯

Shape1.FillColor = &H4000& '暗绿
Shape2.FillColor = &H8080& '暗黄
Shape3.FillColor = &H40& '暗红

Shape1.Shape = 3 '圆形
Shape2.Shape = 3
Shape3.Shape = 3

Command1.Caption = "开始"
Timer1.Interval = 1000 '一秒一次加入倒计时
Timer1.Enabled = False
End Sub

Private Sub Timer1_Timer()
Sj = Sj + 1
If ZT = 1 Or ZT = 3 Then Command1.Caption = (20 - Sj) & "停止"
If ZT = 2 Then Command1.Caption = (5 - Sj) & "停止"
If Sj = 20 And (ZT = 1 Or ZT = 3) Then
Shape1.FillColor = &H4000&
Shape2.FillColor = &H8080&
Shape3.FillColor = &H40&

Select Case ZT

Case 1

Shape2.FillColor = &HFFFF&
ZT = 2
Qzt = 1

Case 3

Shape2.FillColor = &HFFFF&
ZT = 2
Qzt = 3
End Select
Sj = 0
End If
If Sj = 5 And ZT = 2 Then
Shape1.FillColor = &H4000&
Shape2.FillColor = &H8080&
Shape3.FillColor = &H40&

If Qzt = 3 Then
Shape1.FillColor = &HFF00&
ZT = 1
Else
Shape3.FillColor = &HFF&
ZT = 3
End If
Sj = 0
End If

End Sub

热心网友 时间:2023-10-13 22:25

窗体上随意放一个计时器(Timer)和三个Shape控件,还有一个按钮:

Private Sub Command1_Click()
Timer1.Enabled = True
Timer1_Timer
End Sub

Private Sub Form_Load()
Shape1.Shape = 3
Shape1.FillColor = vbGrayText
Shape1.FillStyle = 0
Shape2.Shape = 3
Shape2.FillColor = vbGrayText
Shape2.FillStyle = 0
Shape3.Shape = 3
Shape3.FillColor = vbGrayText
Shape3.FillStyle = 0
Shape1.Move Me.Width / 2 - 500, Me.Height / 6 - 500, 1000, 1000
Shape2.Move Me.Width / 2 - 500, Me.Height / 3 - 500, 1000, 1000
Shape3.Move Me.Width / 2 - 500, Me.Height / 2 - 500, 1000, 1000
Timer1.Enabled = False
Timer1.Interval = 1000
End Sub

Private Sub Timer1_Timer()
Static n As Integer
n = n + 1
If n > 45 Then n = 1
Select Case n
Case 1 To 20
Me.Caption = n
Shape1.FillColor = vbRed
Shape2.FillColor = vbGrayText
Shape3.FillColor = vbGrayText
Case 21 To 25
Me.Caption = n - 20
Shape1.FillColor = vbGrayText
Shape2.FillColor = vbYellow
Shape3.FillColor = vbGrayText
Case 26 To 45
Me.Caption = n - 25
Shape1.FillColor = vbGrayText
Shape2.FillColor = vbGrayText
Shape3.FillColor = vbGreen
End Select
End Sub

热心网友 时间:2023-10-13 22:26

Private Sub Command1_Click()
Timer1.Enabled = False
End Sub

Private Sub Form_Load()
Shape1.BorderColor = &HFF00&
Shape1.FillColor = &HFF00&
Command1.Caption = "停止"
Timer1.Enabled = True
Timer1.Interval = 1
End Sub

Private Sub Timer1_Timer()
If Shape1.BorderColor = 255 Then
Timer1.Interval = 5000
Shape1.BorderColor = 65535
Shape1.FillColor = 65535
Exit Sub
End If
If Shape1.BorderColor = 65280 Then
Timer1.Interval = 20000
Shape1.BorderColor = 255
Shape1.FillColor = 255
Exit Sub
End If
If Shape1.BorderColor = 65535 Then
Timer1.Interval = 20000
Shape1.BorderColor = 65280
Shape1.FillColor = 65280
Exit Sub
End If
End Sub

热心网友 时间:2023-10-13 22:25

'ZT是当前状态记录,Qzt是前状态记录,SJ是时间记录
Dim ZT As Integer, Qzt As Integer, Sj As Integer
Private Sub Command1_Click()
If Command1.Caption = "开始" Then
Command1.Caption = "20停止"
Timer1.Enabled = True
Shape3.FillColor = &HFF&
ZT = 3
Qzt = 3
Else
Command1.Caption = "开始"
Timer1.Enabled = False
Shape1.FillColor = &H4000&
Shape2.FillColor = &H8080&
Shape3.FillColor = &H40&
ZT = 0
End If

End Sub

Private Sub Form_Load()
Shape1.FillStyle = 0 '绿灯
Shape2.FillStyle = 0 '黄灯
Shape3.FillStyle = 0 '红灯

Shape1.FillColor = &H4000& '暗绿
Shape2.FillColor = &H8080& '暗黄
Shape3.FillColor = &H40& '暗红

Shape1.Shape = 3 '圆形
Shape2.Shape = 3
Shape3.Shape = 3

Command1.Caption = "开始"
Timer1.Interval = 1000 '一秒一次加入倒计时
Timer1.Enabled = False
End Sub

Private Sub Timer1_Timer()
Sj = Sj + 1
If ZT = 1 Or ZT = 3 Then Command1.Caption = (20 - Sj) & "停止"
If ZT = 2 Then Command1.Caption = (5 - Sj) & "停止"
If Sj = 20 And (ZT = 1 Or ZT = 3) Then
Shape1.FillColor = &H4000&
Shape2.FillColor = &H8080&
Shape3.FillColor = &H40&

Select Case ZT

Case 1

Shape2.FillColor = &HFFFF&
ZT = 2
Qzt = 1

Case 3

Shape2.FillColor = &HFFFF&
ZT = 2
Qzt = 3
End Select
Sj = 0
End If
If Sj = 5 And ZT = 2 Then
Shape1.FillColor = &H4000&
Shape2.FillColor = &H8080&
Shape3.FillColor = &H40&

If Qzt = 3 Then
Shape1.FillColor = &HFF00&
ZT = 1
Else
Shape3.FillColor = &HFF&
ZT = 3
End If
Sj = 0
End If

End Sub

热心网友 时间:2023-10-13 22:25

窗体上随意放一个计时器(Timer)和三个Shape控件,还有一个按钮:

Private Sub Command1_Click()
Timer1.Enabled = True
Timer1_Timer
End Sub

Private Sub Form_Load()
Shape1.Shape = 3
Shape1.FillColor = vbGrayText
Shape1.FillStyle = 0
Shape2.Shape = 3
Shape2.FillColor = vbGrayText
Shape2.FillStyle = 0
Shape3.Shape = 3
Shape3.FillColor = vbGrayText
Shape3.FillStyle = 0
Shape1.Move Me.Width / 2 - 500, Me.Height / 6 - 500, 1000, 1000
Shape2.Move Me.Width / 2 - 500, Me.Height / 3 - 500, 1000, 1000
Shape3.Move Me.Width / 2 - 500, Me.Height / 2 - 500, 1000, 1000
Timer1.Enabled = False
Timer1.Interval = 1000
End Sub

Private Sub Timer1_Timer()
Static n As Integer
n = n + 1
If n > 45 Then n = 1
Select Case n
Case 1 To 20
Me.Caption = n
Shape1.FillColor = vbRed
Shape2.FillColor = vbGrayText
Shape3.FillColor = vbGrayText
Case 21 To 25
Me.Caption = n - 20
Shape1.FillColor = vbGrayText
Shape2.FillColor = vbYellow
Shape3.FillColor = vbGrayText
Case 26 To 45
Me.Caption = n - 25
Shape1.FillColor = vbGrayText
Shape2.FillColor = vbGrayText
Shape3.FillColor = vbGreen
End Select
End Sub

热心网友 时间:2023-10-13 22:25

'ZT是当前状态记录,Qzt是前状态记录,SJ是时间记录
Dim ZT As Integer, Qzt As Integer, Sj As Integer
Private Sub Command1_Click()
If Command1.Caption = "开始" Then
Command1.Caption = "20停止"
Timer1.Enabled = True
Shape3.FillColor = &HFF&
ZT = 3
Qzt = 3
Else
Command1.Caption = "开始"
Timer1.Enabled = False
Shape1.FillColor = &H4000&
Shape2.FillColor = &H8080&
Shape3.FillColor = &H40&
ZT = 0
End If

End Sub

Private Sub Form_Load()
Shape1.FillStyle = 0 '绿灯
Shape2.FillStyle = 0 '黄灯
Shape3.FillStyle = 0 '红灯

Shape1.FillColor = &H4000& '暗绿
Shape2.FillColor = &H8080& '暗黄
Shape3.FillColor = &H40& '暗红

Shape1.Shape = 3 '圆形
Shape2.Shape = 3
Shape3.Shape = 3

Command1.Caption = "开始"
Timer1.Interval = 1000 '一秒一次加入倒计时
Timer1.Enabled = False
End Sub

Private Sub Timer1_Timer()
Sj = Sj + 1
If ZT = 1 Or ZT = 3 Then Command1.Caption = (20 - Sj) & "停止"
If ZT = 2 Then Command1.Caption = (5 - Sj) & "停止"
If Sj = 20 And (ZT = 1 Or ZT = 3) Then
Shape1.FillColor = &H4000&
Shape2.FillColor = &H8080&
Shape3.FillColor = &H40&

Select Case ZT

Case 1

Shape2.FillColor = &HFFFF&
ZT = 2
Qzt = 1

Case 3

Shape2.FillColor = &HFFFF&
ZT = 2
Qzt = 3
End Select
Sj = 0
End If
If Sj = 5 And ZT = 2 Then
Shape1.FillColor = &H4000&
Shape2.FillColor = &H8080&
Shape3.FillColor = &H40&

If Qzt = 3 Then
Shape1.FillColor = &HFF00&
ZT = 1
Else
Shape3.FillColor = &HFF&
ZT = 3
End If
Sj = 0
End If

End Sub

热心网友 时间:2023-10-13 22:25

窗体上随意放一个计时器(Timer)和三个Shape控件,还有一个按钮:

Private Sub Command1_Click()
Timer1.Enabled = True
Timer1_Timer
End Sub

Private Sub Form_Load()
Shape1.Shape = 3
Shape1.FillColor = vbGrayText
Shape1.FillStyle = 0
Shape2.Shape = 3
Shape2.FillColor = vbGrayText
Shape2.FillStyle = 0
Shape3.Shape = 3
Shape3.FillColor = vbGrayText
Shape3.FillStyle = 0
Shape1.Move Me.Width / 2 - 500, Me.Height / 6 - 500, 1000, 1000
Shape2.Move Me.Width / 2 - 500, Me.Height / 3 - 500, 1000, 1000
Shape3.Move Me.Width / 2 - 500, Me.Height / 2 - 500, 1000, 1000
Timer1.Enabled = False
Timer1.Interval = 1000
End Sub

Private Sub Timer1_Timer()
Static n As Integer
n = n + 1
If n > 45 Then n = 1
Select Case n
Case 1 To 20
Me.Caption = n
Shape1.FillColor = vbRed
Shape2.FillColor = vbGrayText
Shape3.FillColor = vbGrayText
Case 21 To 25
Me.Caption = n - 20
Shape1.FillColor = vbGrayText
Shape2.FillColor = vbYellow
Shape3.FillColor = vbGrayText
Case 26 To 45
Me.Caption = n - 25
Shape1.FillColor = vbGrayText
Shape2.FillColor = vbGrayText
Shape3.FillColor = vbGreen
End Select
End Sub

热心网友 时间:2023-10-13 22:26

Private Sub Command1_Click()
Timer1.Enabled = False
End Sub

Private Sub Form_Load()
Shape1.BorderColor = &HFF00&
Shape1.FillColor = &HFF00&
Command1.Caption = "停止"
Timer1.Enabled = True
Timer1.Interval = 1
End Sub

Private Sub Timer1_Timer()
If Shape1.BorderColor = 255 Then
Timer1.Interval = 5000
Shape1.BorderColor = 65535
Shape1.FillColor = 65535
Exit Sub
End If
If Shape1.BorderColor = 65280 Then
Timer1.Interval = 20000
Shape1.BorderColor = 255
Shape1.FillColor = 255
Exit Sub
End If
If Shape1.BorderColor = 65535 Then
Timer1.Interval = 20000
Shape1.BorderColor = 65280
Shape1.FillColor = 65280
Exit Sub
End If
End Sub

热心网友 时间:2023-10-13 22:26

Private Sub Command1_Click()
Timer1.Enabled = False
End Sub

Private Sub Form_Load()
Shape1.BorderColor = &HFF00&
Shape1.FillColor = &HFF00&
Command1.Caption = "停止"
Timer1.Enabled = True
Timer1.Interval = 1
End Sub

Private Sub Timer1_Timer()
If Shape1.BorderColor = 255 Then
Timer1.Interval = 5000
Shape1.BorderColor = 65535
Shape1.FillColor = 65535
Exit Sub
End If
If Shape1.BorderColor = 65280 Then
Timer1.Interval = 20000
Shape1.BorderColor = 255
Shape1.FillColor = 255
Exit Sub
End If
If Shape1.BorderColor = 65535 Then
Timer1.Interval = 20000
Shape1.BorderColor = 65280
Shape1.FillColor = 65280
Exit Sub
End If
End Sub

热心网友 时间:2023-10-13 22:25

'ZT是当前状态记录,Qzt是前状态记录,SJ是时间记录
Dim ZT As Integer, Qzt As Integer, Sj As Integer
Private Sub Command1_Click()
If Command1.Caption = "开始" Then
Command1.Caption = "20停止"
Timer1.Enabled = True
Shape3.FillColor = &HFF&
ZT = 3
Qzt = 3
Else
Command1.Caption = "开始"
Timer1.Enabled = False
Shape1.FillColor = &H4000&
Shape2.FillColor = &H8080&
Shape3.FillColor = &H40&
ZT = 0
End If

End Sub

Private Sub Form_Load()
Shape1.FillStyle = 0 '绿灯
Shape2.FillStyle = 0 '黄灯
Shape3.FillStyle = 0 '红灯

Shape1.FillColor = &H4000& '暗绿
Shape2.FillColor = &H8080& '暗黄
Shape3.FillColor = &H40& '暗红

Shape1.Shape = 3 '圆形
Shape2.Shape = 3
Shape3.Shape = 3

Command1.Caption = "开始"
Timer1.Interval = 1000 '一秒一次加入倒计时
Timer1.Enabled = False
End Sub

Private Sub Timer1_Timer()
Sj = Sj + 1
If ZT = 1 Or ZT = 3 Then Command1.Caption = (20 - Sj) & "停止"
If ZT = 2 Then Command1.Caption = (5 - Sj) & "停止"
If Sj = 20 And (ZT = 1 Or ZT = 3) Then
Shape1.FillColor = &H4000&
Shape2.FillColor = &H8080&
Shape3.FillColor = &H40&

Select Case ZT

Case 1

Shape2.FillColor = &HFFFF&
ZT = 2
Qzt = 1

Case 3

Shape2.FillColor = &HFFFF&
ZT = 2
Qzt = 3
End Select
Sj = 0
End If
If Sj = 5 And ZT = 2 Then
Shape1.FillColor = &H4000&
Shape2.FillColor = &H8080&
Shape3.FillColor = &H40&

If Qzt = 3 Then
Shape1.FillColor = &HFF00&
ZT = 1
Else
Shape3.FillColor = &HFF&
ZT = 3
End If
Sj = 0
End If

End Sub

热心网友 时间:2023-10-13 22:25

窗体上随意放一个计时器(Timer)和三个Shape控件,还有一个按钮:

Private Sub Command1_Click()
Timer1.Enabled = True
Timer1_Timer
End Sub

Private Sub Form_Load()
Shape1.Shape = 3
Shape1.FillColor = vbGrayText
Shape1.FillStyle = 0
Shape2.Shape = 3
Shape2.FillColor = vbGrayText
Shape2.FillStyle = 0
Shape3.Shape = 3
Shape3.FillColor = vbGrayText
Shape3.FillStyle = 0
Shape1.Move Me.Width / 2 - 500, Me.Height / 6 - 500, 1000, 1000
Shape2.Move Me.Width / 2 - 500, Me.Height / 3 - 500, 1000, 1000
Shape3.Move Me.Width / 2 - 500, Me.Height / 2 - 500, 1000, 1000
Timer1.Enabled = False
Timer1.Interval = 1000
End Sub

Private Sub Timer1_Timer()
Static n As Integer
n = n + 1
If n > 45 Then n = 1
Select Case n
Case 1 To 20
Me.Caption = n
Shape1.FillColor = vbRed
Shape2.FillColor = vbGrayText
Shape3.FillColor = vbGrayText
Case 21 To 25
Me.Caption = n - 20
Shape1.FillColor = vbGrayText
Shape2.FillColor = vbYellow
Shape3.FillColor = vbGrayText
Case 26 To 45
Me.Caption = n - 25
Shape1.FillColor = vbGrayText
Shape2.FillColor = vbGrayText
Shape3.FillColor = vbGreen
End Select
End Sub

热心网友 时间:2023-10-13 22:26

Private Sub Command1_Click()
Timer1.Enabled = False
End Sub

Private Sub Form_Load()
Shape1.BorderColor = &HFF00&
Shape1.FillColor = &HFF00&
Command1.Caption = "停止"
Timer1.Enabled = True
Timer1.Interval = 1
End Sub

Private Sub Timer1_Timer()
If Shape1.BorderColor = 255 Then
Timer1.Interval = 5000
Shape1.BorderColor = 65535
Shape1.FillColor = 65535
Exit Sub
End If
If Shape1.BorderColor = 65280 Then
Timer1.Interval = 20000
Shape1.BorderColor = 255
Shape1.FillColor = 255
Exit Sub
End If
If Shape1.BorderColor = 65535 Then
Timer1.Interval = 20000
Shape1.BorderColor = 65280
Shape1.FillColor = 65280
Exit Sub
End If
End Sub
声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com
四川省综合素质a级证书? 华为手机怎么还原微信聊天记录 华为手机微信内容恢复方法 股权转让的主要方式有哪些 股权转让有哪几种方式 股东转让的几种形式是 股东转让的几种形式 高考多少分能上衡阳师范学院南岳学院 你们被玖富金融骗,后期有还款吗? 玖富悟空理财2022年最新消息还有希望吗?悟空理财最新情况(悟空理财可信... 同等责任交通事故致人死亡是否追究刑事责任 java中有的代码是红色的,好像是代表关键字吧?那蓝色的代码代表什么呢? 使用js 搜索页面 相关词变为红色 代码怎么写?? 编程,在网页上以红色显示日期时间,星期,代码求解答 在vb编程中。代码是红色的。错在哪里? 请好心人解答!谢谢! 表示的红色的代码都有哪些形式的? 老公婚前商业贷款买房,婚后可以用老婆的公积金转成公积金贷款吗 我买的二手房价格是50万,请问要交多少钱的税费? 第一次买二手房也是首次买房48万首付要多少钱? 名下有房再买一套二手房和名下无房买二手房过户费有什么区别? 长春二手房,产权过二,48平,28.7万元,请问更名费要多少钱 德阳乡镇双产权门面房.210个平方,48万需要多少钱过户 永康40平方未满5年二手房过户需多少钱。售价48万 父母不在了,房产证是父母的,如果过户到自己名下,大概都有哪些费用?举例85平方的房子,需要多少费用 48平米的房子二手房过户需要多少钱没有大税? 百度输入法中的“三维词库”是什么意思 百度输入法的云输入法有什么用? 百度输入法和搜狗输入法有哪些区别 百度输入法是什么意思 一般纳税人的税率怎么计算? 企业一般纳税人怎么收税 编程实现,从红,黄,蓝,绿四种颜色中任选三种不同的颜色,共有多少种取法,并输出所有的排列 当编程时,程序代码以红色显示,是什么错误? KEIL软件程序里出现红色代表什么意思? 怎样问女生是否有男朋友 java里面GUI编程红色框里面的new是什么意思什么用法什么操作类做参数吗? C# 有关于字体颜色的编程 我用的S7-300 西门子PLC 编写程序代码的时候怎么出现红色错误,不知道为什么? 怎么问女孩子有没有男朋友比较好 eclipse 下编程的时候 代码下有红色波浪号表示 什么意思 零下温度在室外打球的感觉好吗? 怎么询问一个女生是否有男朋友 用c++编程,求代码 冬天适合在室外打球吗??? 如何才能巧妙的问一个女孩子有没有男朋友呢 编程序如何把红色42一下提出来 冬天在室外打网球好不 C语言编程中的字体颜色是什么意思 冬天在室外刚打完篮球的男生该注意什么? 冬天能打网球吗? 冬天在室外可以打篮球吗