การเขียนโปรแกรม
coding
โค้ดในปุ่ม BtnSpin
Private Sub BtnSpin_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles BtnSpin.Click
Dim i As Int16 = 1
If
RHi.Checked = False And RMid.Checked = False And RLow.Checked
= False Then
MsgBox("กรุณาเลือก
สูง กลาง หรือ ต่ำ ก่อน")
Else
For
i = 1 To 100 * Tbspeed.Value
If
stopSpin = True Then
Exit
For
Else
B1.Text
= Int(Rnd() * 6) + 1
B2.Text
= Int(Rnd() * 6) + 1
B3.Text
= Int(Rnd() * 6) + 1
Application.DoEvents()
End
If
Next
i
LbResult.Text
= Int(B1.Text) + Int(B2.Text) + Int(B3.Text)
Select
Case True
Case
RHi.Checked = True
If
Int(LbResult.Text) > 11 Then
LbInfo.Text
= "You Win !"
Else
LbInfo.Text
= "You Lose !"
End
If
Case
RMid.Checked = True
If
Int(LbResult.Text) = 11 Then
LbInfo.Text
= "You Win !"
Else
LbInfo.Text
= "You Lose !"
End
If
Case
RLow.Checked = True
If
Int(LbResult.Text) < 11 Then
LbInfo.Text
= "You Win !"
Else
LbInfo.Text
= "You Lose !"
End
If
End
Select
stopSpin
= False
End
If
End Sub
โค้ดตอน โหลดฟอร์มขึ้นมา
Private Sub Form1_Load(ByVal sender
As System.Object, ByVal e As System.EventArgs) Handles
MyBase.Load
stopSpin
= False
End Sub
โค้ดในปุ่ม BtnStop
Private Sub BtnStop_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles BtnStop.Click
stopSpin
= True
End Sub
|