第05课 随机函数及其应用

“哭还是笑？”代码

返回

> Form1

> Private Sub Command2_Click() '对应于“翻”那个按钮 ，这里利用循环随机产生36个随机小数，大于0.5的就表示产生了一个笑脸，小于0.5就表示产生了一个哭脸。

> For i = 0 To 35
> y = Rnd
> If y > 0.5 Then
> Command1(i).Picture = Image1.Picture
> Else
> Command1(i).Picture = Image2.Picture
> End If
> Next i
> '---------------------------------------
> xi = 0
> ku = 0
> For i = 0 To 35
> If Command1(i).Picture = Image1.Picture Then
> xi = xi + 1
> Else
> ku = ku + 1
> End If
> Next i
> Text1.Text = xi
> Text2.Text = ku
> If Val(Text3.Text) = Val(Text1.Text) Then
> Form2.Show
> Else
> If Val(Text3.Text) < Val(Text1.Text) Then
> Form3.Label2.Caption = "小了!"
> Else
> Form3.Label2.Caption = "大了!"
> End If
> Form3.Show
> End If
> End Sub

> Private Sub Form_Activate()
> Text3.SetFocus
> End Sub

> 这里用到了一个循环语句：For/Next

> Form2

> Private Sub Command1_Click()
> Form2.Hide
> Form1.Text3.Text = ""
> Form1.Text1.Text = ""
> Form1.Text2.Text = ""
> For i = 0 To 35
> Form1.Command1(i).Picture =Form1.Image5.Picture
> Next i
> Form1.Show
> End Sub
> Private Sub Command2_Click()
> End
> End Sub

> Form3

> Private Sub Command1_Click()
> Form3.Hide
> Form1.Text3.Text = ""
> Form1.Text1.Text = ""
> Form1.Text2.Text = ""
> For i = 0 To 35
> Form1.Command1(i).Picture = Form1.Image5.Picture
> Next i
> Form1.Show
> End Sub
> Private Sub Command2_Click()
> End
> End Sub