📄 code.txt
字号:
Dim i, j, k, a As Integer
Dim full As Integer
Dim emputy As Integer
Private Sub Command11_Click()
MsgBox "该软件由林夕梦设计制作;联系方式:cgq@sdau.edu.cn", , "关于"
End Sub
Private Sub Command2_Click() '消费按钮
Command4.Visible = True
If Label6.Caption = "1" Then '判断缓冲池是否为空
If Label8.Caption = "" Then
MsgBox "没有产品可以消费", , "提示"
End If
MsgBox "互斥!不能消费!", , "提示"
Else
Timer2.Interval = 1500 '时钟控件开始
Label6.Caption = "1"
Label14.Caption = "消费者消费了一个产品"
End If
End Sub
Private Sub Command3_Click()
End
'退出按钮
End Sub
Private Sub Command4_Click()
'生产按钮
Label13.Caption = "生产者生产了一个产品,申请一个缓冲池"
'平判断缓冲池是否满
If Val(Label8.Caption) < 6 Then
Timer3.Interval = 1500
Label6.Caption = 1
If Label1(a).BackColor = &HFF& Then
Label14.Caption = "消费者消费了一个产品"
End If
Else
'提示
MsgBox "缓冲池已满", , "提示"
a = 0
j = 0
End If
End Sub
Private Sub Form_Load()
full = 0
emputy = 6 'emputy 理解为"空"的意思
Timer1.Interval = 0
Timer2.Interval = 0
Label2.Caption = 6
Label8.Caption = 0
End Sub
Private Sub Timer1_Timer() '生产过程中的时钟控件
If i > 5 Then '判断缓冲池是否满
MsgBox "缓冲池已满", , "提示"
Label6.Caption = "0"
Timer1.Interval = 0
Else
'不满进行生产
emputy = emputy - 1
full = full + 1
Label1(i).BackColor = &HFF00&
Label6.Caption = 1
Label2.Caption = emputy
Label8.Caption = full
i = i + 1
Label13.Caption = ""
Timer1.Interval = 0
End If
End Sub
Private Sub Timer2_Timer() '消费过程的时钟控件
If Val(Label8.Caption) = 0 Then
'缓冲池是否空
MsgBox "没有产品可供消费", , "提示"
Label6.Caption = 0
Label14.Caption = ""
Timer2.Interval = 0
Else
'不空进行消费
emputy = emputy + 1
full = full - 1
Label1(j).BackColor = &HFF&
j = j + 1
Label14.Caption = ""
Label6.Caption = 0
Label2.Caption = emputy
Label8.Caption = full
Timer2.Interval = 0
End If
End Sub
Private Sub Timer3_Timer() '生产过程的时钟控件
'当前操作的缓冲池后面的缓冲池是否为空,不空指针后移
If Label1(a).BackColor = &HFF00& Then
a = a + 1
If Label1(a).BackColor = &HFF00& Then
a = a + 1
If Label1(a).BackColor = &HFF00& Then
a = a + 1
If Label1(a).BackColor = &HFF00& Then
a = a + 1
End If
End If
End If
Label1(a).BackColor = &HFF00&
a = a + 1
emputy = emputy - 1
full = full + 1
Else
Label1(a).BackColor = &HFF00&
a = a + 1
emputy = emputy - 1
full = full + 1
End If
k = a
Label6.Caption = 0
Label2.Caption = emputy
Label8.Caption = full
Label13.Caption = ""
Timer3.Interval = 0
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -