Yahoo奇摩知識+ 將於 2021 年 5 月 4 日 (美國東部時間) 終止服務。自 2021 年 4 月 20 日 (美國東部時間) 起,Yahoo奇摩知識+ 網站將會轉為唯讀模式。其他 Yahoo奇摩產品與服務或您的 Yahoo奇摩帳號都不會受影響。如需關於 Yahoo奇摩知識+ 停止服務以及下載您個人資料的資訊,請參閱說明網頁。

花兒 發問時間: 電腦與網際網路程式設計 · 2 0 年前

誰會寫VB程式........教教我唄!急~~~~~

誰會用VB寫剪刀石頭布的程式?教教我吧.....急!簡易的就行了 thanks!

1 個解答

評分
  • W.J.S.
    Lv 7
    2 0 年前
    最佳解答

    Dim WithEvents L1 As CommandButton, WithEvents L2 As CommandButton, WithEvents L3 As CommandButton

    Dim L As Label

    Private Sub Form_Load()

    Set L = Controls.Add("Vb.Label", "L")

    L = "電腦": L.BorderStyle = 1: L.Alignment = 2: L.WordWrap = True: L.Visible = True

    Set L1 = Controls.Add("Vb.CommandButton", "L1")

    L1.Caption = "剪刀": L1.Top = L.Height + 30: L1.Tag = 0: L1.Visible = True

    Set L2 = Controls.Add("Vb.CommandButton", "L2")

    L2.Caption = "石頭": L2.Top = L1.Top: L2.Left = L1.Width + 30: L2.Tag = 1: L2.Visible = True

    Set L3 = Controls.Add("Vb.CommandButton", "L3")

    L3.Caption = "布": L3.Top = L1.Top: L3.Left = L2.Left + L2.Width + 30: L3.Tag = 2: L3.Visible = True

    L.Width = L3.Left + L3.Width

    End Sub

    Sub Cal(N)

    Dim I As Integer, S As String

    Randomize

    I = Int(Rnd * 3)

    L = "電腦出 " & Switch(I = 0, "剪刀", I = 1, "石頭", I = 2, "布") & vbCrLf

    If I = N Then

     L = L & "雙方平手"

    ElseIf I > N Then

     If I - N = 1 Then

      L = L & "電腦贏"

     Else

      L = L & "電腦輸"

     End If

    Else

     If N - I = 1 Then

      L = L & "電腦輸"

     Else

      L = L & "電腦贏"

     End If

    End If

    End Sub

    Private Sub L1_Click()

    Cal L1.Tag

    End Sub

    Private Sub L2_Click()

    Cal L2.Tag

    End Sub

    Private Sub L3_Click()

    Cal L3.Tag

    End Sub

還有問題?馬上發問,尋求解答。