
Private Sub Command1_Click() '窗体上放一个按钮,点击,就可以在窗体上打印结果
Dim SuShu(3) As Integer, i1 As Integer, i2 As Integer, i3 As Integer, i4 As Integer, i5 As Integer, c1 As Long, c2 As Long, Ji1 As Long, Ji2 As Long, Ji3 As Long
MeAutoRedraw = True
SuShu(0) = 2: SuShu(1) = 3: SuShu(1) = 5: SuShu(3) = 7
For i1 = 0 To 3
For i2 = 0 To 3
For i3 = 0 To 3
c1 = SuShu(i1) 100 + SuShu(i2) 10 + SuShu(i3)
For i4 = 0 To 3
For i5 = 0 To 3
c2 = SuShu(i4) 10 + SuShu(i5)
Ji1 = c1 SuShu(i5)
Ji2 = c1 SuShu(i4)
Ji3 = Ji1 + Ji2 10
If Ji1 > 1000 And Ji2 > 1000 And Ji3 > 10000 Then
If IsQuanSuShu(Ji1) And IsQuanSuShu(Ji2) And IsQuanSuShu(Ji3) Then '如果是,输出结果
Print " " & CStr(c1) & vbNewLine & " X " & CStr(c2) & vbNewLine & "--------"
Print " " & CStr(Ji1) & vbNewLine & " " & CStr(Ji2) & vbNewLine & "--------" & vbNewLine & " " & CStr(Ji3)
End If
End If
Next
Next
Next
Next
Next
End Sub
Private Function IsQuanSuShu(ByVal n As Long) As Boolean '每一位是否全部是2,3,5,7
Dim k As Integer
Do While n > 0
k = n Mod 10
If k <> 2 And k <> 3 And k <> 5 And k <> 7 Then Exit Function
n = n \ 10
Loop
IsQuanSuShu = True
End Function
程序并没有实现,显示中绿灯和黄灯会闪的功能,本人初学者,以后多交流。
设计如下图,两个计时器(enabled为false),三个标签,两个文本框,一个按钮
运行效果:
代码如下:
Dim n As Integer '控制哪个灯亮Dim bool1 As Boolean '两个变量一起控制是否开始运行程序
Dim bool2 As Boolean
Dim b As Integer
Private Sub Command1_Click() '只有两个文本框同时满足输入的时间在1-10秒范围内,才开始运行
If IsNumeric(Text1Text) Then
bool1 = True
Else
MsgBox "输入的不是数字,重新输入红灯的时间"
Text1Text = ""
End If
If IsNumeric(Text2Text) Then
bool2 = True
Else
MsgBox "输入的不是数字,重新输入绿灯时间"
Text2Text = ""
End If
If bool1 And bool2 Then
Timer1Enabled = True
Timer1Interval = 1
End If
End Sub
Private Sub Form_Load() '重新定义窗体坐标,画出三个灯都没有亮的状态下的红绿灯
bool1 = False
bool2 = False
AutoRedraw = True
Form1Cls
Form1Scale (0, 0)-(100, 100)
Form1FillStyle = 0
n = 1
Form1FillColor = RGB(0, 0, 0)
Form1Line (2, 2)-(18, 48), , B
Form1FillColor = RGB(160, 0, 0)
Form1Circle (10, 10), 5, RGB(160, 0, 0)
Form1FillColor = RGB(0, 160, 0)
Form1Circle (10, 40), 5, RGB(0, 160, 0)
Form1FillColor = RGB(160, 160, 0)
Form1Circle (10, 25), 5, RGB(160, 160, 0)
End Sub
Private Sub Timer1_Timer()
n = n Mod 3
If n = 1 Then '红色高亮显示,其他变暗
Form1Cls
Form1FillColor = RGB(0, 0, 0)
Form1Line (2, 2)-(18, 48), , B
Form1FillColor = RGB(255, 0, 0)
Form1Circle (10, 10), 5, RGB(255, 0, 0)
Form1FillColor = RGB(0, 160, 0)
Form1Circle (10, 40), 5, RGB(0, 160, 0)
Form1FillColor = RGB(160, 160, 0)
Form1Circle (10, 25), 5, RGB(160, 160, 0)
Timer1Interval = Val(Text1Text) 1000
b = Val(Text1Text)
Timer2Enabled = True
ElseIf n = 0 Then '**高亮显示,其他变暗
Form1Cls
Form1FillColor = RGB(0, 0, 0)
Form1Line (2, 2)-(18, 48), , B
Form1FillColor = RGB(255, 255, 0)
Form1Circle (10, 25), 5, RGB(255, 255, 0)
Form1FillColor = RGB(0, 160, 0)
Form1Circle (10, 40), 5, RGB(0, 160, 0)
Form1FillColor = RGB(160, 0, 0)
Form1Circle (10, 10), 5, RGB(160, 0, 0)
Timer1Interval = 3000
b = 3
Timer2Enabled = True
Else '绿色高亮显示,其他变暗
Form1Cls
Form1FillColor = RGB(0, 0, 0)
Form1Line (2, 2)-(18, 48), , B
Form1FillColor = RGB(0, 255, 0)
Form1Circle (10, 40), 5, RGB(0, 255, 0)
Form1FillColor = RGB(160, 0, 0)
Form1Circle (10, 10), 5, RGB(160, 0, 0)
Form1FillColor = RGB(160, 160, 0)
Form1Circle (10, 25), 5, RGB(160, 160, 0)
Timer1Interval = Val(Text2Text) 1000
b = Val(Text2Text)
Timer2Enabled = True
End If
n = n + 1
End Sub
Private Sub Timer2_Timer()
b = b - 1
If b <= 10 Then
Label3Caption = b
End If
If b = 0 Then
Timer2Enabled = False
Label3Caption = ""
End If
End Sub
以上就是关于用vb编写程序全部的内容,包括:用vb编写程序、VB程序编写、等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)