下列程序的功能是:当用户点击窗体下方的“石头”(command1)、“剪子”(command2)、“布”(command3)任意一个按钮的时候,电脑也会在Label1上随机显示出一个石头、剪刀、布(显示在label1上),程序判断出胜负(平局算负)将结果显示到label3上。
Private Sub Command1_Click()
Label1.Caption = sj ‘计算机随机产生一个值
Label2.Caption = Command1.Caption
If cp(Label1.Caption, Label2.Caption) Then ‘判断胜负
{#blank#}1{#/blank#} = "乙方负"
Else
Label3.Caption = "乙方胜"
End If
End Sub
Function sj() As String '随机生成石头、剪刀、布
i = {#blank#}2{#/blank#} ‘随机生成1~3任一整数
If i = 1 Then sj = "石头"
If i = 2 Then sj = "剪刀"
If i = 3 Then sj = "布"
End Function