سجاد سیدی
2 سال پیش توسط سجاد سیدی مطرح شد
1 پاسخ

کد vb پاور پوینت

من کد vb در پاور پوینت دارم:
قرار بازی دوز باشه.
۹ تا commandbutton به نام های cb1 تا cb9 که از وجود همشون مطمینم
ولی کد ارور runtime 424 میده
کد دو قسمت داره:
قسمت عمومی:

Dim turn As Integer
Sub checkForWinner()
    ' Check rows
    If (cb1.Caption = cb2.Caption And cb2.Caption = cb3.Caption) Then
        winner cb1.Caption
    ElseIf (cb4.Caption = cb5.Caption And cb5.Caption = cb6.Caption) Then
        winner cb4.Caption
    ElseIf (cb7.Caption = cb8.Caption And cb8.Caption = cb9.Caption) Then
        winner cb7.Caption
    ' Check columns
    ElseIf (cb1.Caption = cb4.Caption And cb4.Caption = cb7.Caption) Then
        winner cb1.Caption
    ElseIf (cb2.Caption = cb5.Caption And cb5.Caption = cb8.Caption) Then
        winner cb2.Caption
    ElseIf (cb3.Caption = cb6.Caption And cb6.Caption = cb9.Caption) Then
        winner cb3.Caption
    ' Check diagonals
    ElseIf (cb1.Caption = cb5.Caption And cb5.Caption = cb9.Caption) Then
        winner cb1.Caption
    ElseIf (cb3.Caption = cb5.Caption And cb5.Caption = cb7.Caption) Then
        winner cb3.Caption
    ' Check for draw
    ElseIf turn >= 9 Then
        ActivePresentation.SlideShowWindow.View.GotoSlide (7)
    End If
End Sub
Sub winner(player As String)
    If player = "x" Then
        SlideShowWindows(1).View.GotoSlide (5)
    ElseIf player = "o" Then
        SlideShowWindows(1).View.GotoSlide (6)
    End If
End Sub

قسمت اصلی:

Private Sub cb1_Click()
    If turn Mod 2 = 0 Then
        cb1.Caption = "x"
    Else
        cb1.Caption = "o"
    End If
    turn = turn + 1
    checkForWinner
End Sub
Private Sub cb2_Click()
    If turn Mod 2 = 0 Then
        cb2.Caption = "x"
    Else
        cb2.Caption = "o"
    End If
    turn = turn + 1
    checkForWinner
End Sub
Private Sub cb3_Click()
    If turn Mod 2 = 0 Then
        cb3.Caption = "x"
    Else
        cb3.Caption = "o"
    End If
    turn = turn + 1
    checkForWinner
End Sub
Private Sub cb4_Click()
    If turn Mod 2 = 0 Then
        cb4.Caption = "x"
    Else
        cb4.Caption = "o"
    End If
    turn = turn + 1
    checkForWinner
End Sub
Private Sub cb5_Click()
    If turn Mod 2 = 0 Then
        cb5.Caption = "x"
    Else
        cb5.Caption = "o"
    End If
    turn = turn + 1
    checkForWinner
End Sub
Private Sub cb6_Click()
    If turn Mod 2 = 0 Then
        cb6.Caption = "x"
    Else
        cb6.Caption = "o"
    End If
    turn = turn + 1
    checkForWinner
End Sub
Private Sub cb7_Click()
    If turn Mod 2 = 0 Then
        cb7.Caption = "x"
    Else
        cb7.Caption = "o"
    End If
    turn = turn + 1
    checkForWinner
End Sub
Private Sub cb8_Click()
    If turn Mod 2 = 0 Then
        cb8.Caption = "x"
    Else
        cb8.Caption = "o"
    End If
    turn = turn + 1
    checkForWinner
End Sub
Private Sub cb9_Click()
    If turn Mod 2 = 0 Then
        cb9.Caption = "x"
    Else
        cb9.Caption = "o"
    End If
    turn = turn + 1
    checkForWinner
End Sub

تمام commandbutton ها را چک کردم و وجود دارند
ارور مخصوص قسمت
If (cb1.Caption = cb2.Caption And cb2.Caption = cb3.Caption) Then
است.
ممنون میشم کمکم کنید