如果文件存在则返回其他注释

时间:2015-12-08 02:49:39

标签: php sql

我有以下代码:

Public Class Form1
Dim count, temp, ch, temp2, v1, v2, v3, v4, v5, v6, v7, v8, v9
Dim listOfTextBox As New List(Of TextBox)
Public Sub Start_UP() Handles Me.Load
    Disable_ALL()
End Sub
Private Sub cmdStart_Click(sender As Object, e As EventArgs) Handles cmdStart.Click
    cmdStart.Enabled = False
    Enable_ALL()
    Winner_Display.Text = Nothing
    ch = 1
    count = 0
    temp = 0
    temp2 = 0
    v1 = "0"
    v2 = "0"
    v3 = "0"
    v4 = "0"
    v5 = "0"
    v6 = "0"
    v7 = "0"
    v8 = "0"
    v9 = "0"
End Sub 'start
Public Sub totalcheckwin()
    If v1 = "O" And v2 = "O" And v3 = "O" Or
        v4 = "O" And v5 = "O" And v6 = "O" Or
        v7 = "O" And v8 = "O" And v9 = "O" Or
        v1 = "O" And v4 = "O" And v7 = "O" Or
        v2 = "O" And v5 = "O" And v8 = "O" Or
        v3 = "O" And v6 = "O" And v9 = "O" Or
        v1 = "O" And v5 = "O" And v9 = "O" Or
        v3 = "O" And v5 = "O" And v7 = "O" Then
        Disable_All()

 Winner_Display.Text = "O Wins"
    End If
    If v1 = "X" And v2 = "X" And v3 = "X" Or
        v4 = "X" And v5 = "X" And v6 = "X" Or
        v7 = "X" And v8 = "X" And v9 = "X" Or
        v1 = "X" And v4 = "X" And v7 = "X" Or
        v2 = "X" And v5 = "X" And v8 = "X" Or
        v3 = "X" And v6 = "X" And v9 = "X" Or
        v1 = "X" And v5 = "X" And v9 = "X" Or
        v3 = "X" And v5 = "X" And v7 = "X" Then
        Disable_All()

        Winner_Display.Text = "X Wins"
    End If
End Sub
Public Sub checkcount()
    Hiden_texbox.Focus()

    count = count + 1
    If count = 3 Then
        count = 1
    End If
    If count = 1 Then
        temp = "O"
    Else
        temp = "X"
    End If
    locksqure()
End Sub 'locks squres
Public Sub locksqure()

    If temp2 = "sq1" Then
        If v1 = "O" Or v1 = "X" Then
            Enable_All
            Disable_A()
        Else
            Disable_All
            Enable_A()
        End If
    End If
    If temp2 = "sq2" Then
        If v2 = "O" Or v2 = "X" Then
            Enable_All()
            Disable_B()
        Else
            Disable_All()
            Enable_B()
        End If
    End If
    ' you should get the drift of this bit of code
    permlock()
    totalcheckwin()
End Sub
Public Sub permlock()
    If TextBox1.Text = "O" Or TextBox1.Text = "X" Then
        TextBox1.Enabled = False
    End If
'this code repeats till the textbox is at 81
End Sub

Public Sub Disable_ALL()
    Disable_A()
    Disable_B()
    Disable_C()
    Disable_D()
    Disable_E()
    Disable_F()
    Disable_G()
    Disable_H()
    Disable_I()
End Sub
Public Sub Disable_A()
    For value As Integer = 1 To 9
        dim textbox as new TextBox
        textbox.Name= "TextBox"+value.tostring 
        listOfTextBox.add(textbox) 

           If (value = 9) Then
                Exit For
           End If
    Next

     listofTextBoxes.ForEach(Sub(o)
                            o.BackColor = Color.lightGray
                            o.Enabled = False
                            o.Name = "TextBoxId"
                            End Sub)
End Sub 'disable squre
'This part repeats 9 times and the textbox court goes to 81
Public Sub Enable_ALL()
    Enable_A()
    Enable_B()
    Enable_C()
    Enable_D()
    Enable_E()
    Enable_F()
    Enable_G()
    Enable_H()
    Enable_I()
End Sub
Public Sub Enable_A()
    For value As Integer = 1 To 9
        dim textbox as new TextBox
        textbox.Name= "TextBox"+value.tostring 
        listOfTextBox.add(textbox) 

           If (value = 9) Then
                Exit For
           End If
    Next

     listofTextBoxes.ForEach(Sub(o)
                            o.BackColor = Color.White
                            o.Enabled = True
                            o.Name = "TextBoxId"
                            End Sub)
End Sub 'enable squre
'This part repeats 9 times and the textbox court goes to 81
'the next part just checks if a person has got 3 in a row  and repeats 9 times 
    Public Sub checkwin()
    If TextBox1.Text = "O" And TextBox2.Text = "O" And TextBox3.Text = "O" Or
        TextBox4.Text = "O" And TextBox5.Text = "O" And TextBox6.Text = "O" Or
        TextBox7.Text = "O" And TextBox8.Text = "O" And TextBox9.Text = "O" Or
        TextBox1.Text = "O" And TextBox4.Text = "O" And TextBox7.Text = "O" Or
        TextBox2.Text = "O" And TextBox5.Text = "O" And TextBox8.Text = "O" Or
        TextBox3.Text = "O" And TextBox6.Text = "O" And TextBox9.Text = "O" Or
        TextBox1.Text = "O" And TextBox5.Text = "O" And TextBox9.Text = "O" Or
        TextBox3.Text = "O" And TextBox5.Text = "O" And TextBox7.Text = "O" Then

        TextBox1.Text = "O"
        TextBox2.Text = "O"
        TextBox3.Text = "O"
        TextBox4.Text = "O"
        TextBox5.Text = "X"
        TextBox6.Text = "O"
        TextBox7.Text = "O"
        TextBox8.Text = "O"
        TextBox9.Text = "O"
        Disable_A()
        v1 = "O"
    End If
    If TextBox1.Text = "X" And TextBox2.Text = "X" And TextBox3.Text = "X" Or
        TextBox4.Text = "X" And TextBox5.Text = "X" And TextBox6.Text = "X" Or
        TextBox7.Text = "X" And TextBox8.Text = "X" And TextBox9.Text = "X" Or
        TextBox1.Text = "X" And TextBox4.Text = "X" And TextBox7.Text = "X" Or
        TextBox2.Text = "X" And TextBox5.Text = "X" And TextBox8.Text = "X" Or
        TextBox3.Text = "X" And TextBox6.Text = "X" And TextBox9.Text = "X" Or
        TextBox1.Text = "X" And TextBox5.Text = "X" And TextBox9.Text = "X" Or
        TextBox3.Text = "X" And TextBox5.Text = "X" And TextBox7.Text = "X" Then

        TextBox1.Text = "X"
        TextBox2.Text = "O"
        TextBox3.Text = "X"
        TextBox4.Text = "O"
        TextBox5.Text = "X"
        TextBox6.Text = "O"
        TextBox7.Text = "X"
        TextBox8.Text = "O"
        TextBox9.Text = "X"
        Disable_A()
        v1 = "X"
    End If
    locksqure()
End Sub

   Private Sub resetall()
    Enable_All()
End Sub
Private Sub retext()
    TextBox1.Text = Nothing
    TextBox2.Text = Nothing
    TextBox3.Text = Nothing
' goes till textbox is at 81
        End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
    ch = 0
    resetall()
    retext()
    cmdStart.Enabled = True
End Sub

Private Sub TextBox1_Click(sender As Object, e As EventArgs) Handles TextBox1.Click
    If ch = 1 Then
        temp2 = "sq1"
        checkcount()
        TextBox1.Text = temp
        TextBox1.Enabled = False
        checkwin()
    End If
End Sub '1 squre
Private Sub TextBox2_Click(sender As Object, e As EventArgs) Handles TextBox2.Click
    If ch = 1 Then
        temp2 = "sq2"
        checkcount()
        TextBox2.Text = temp
        TextBox2.Enabled = False
        checkwin()
    End If
End Sub
Private Sub TextBox3_Click(sender As Object, e As EventArgs) Handles TextBox3.Click
    If ch = 1 Then
        temp2 = "sq3"
        checkcount()
        TextBox3.Text = temp
        TextBox3.Enabled = False
        checkwin()
    End If
End Sub
Private Sub TextBox4_Click(sender As Object, e As EventArgs) Handles TextBox4.Click
    If ch = 1 Then
        temp2 = "sq4"
        checkcount()
        TextBox4.Text = temp
        TextBox4.Enabled = False
        checkwin()
    End If
End Sub
Private Sub TextBox5_Click(sender As Object, e As EventArgs) Handles TextBox5.Click
    If ch = 1 Then
        temp2 = "sq5"
        checkcount()
        TextBox5.Text = temp
        TextBox5.Enabled = False
        checkwin()
    End If
End Sub
Private Sub TextBox6_Click(sender As Object, e As EventArgs) Handles TextBox6.Click
    If ch = 1 Then
        temp2 = "sq6"
        checkcount()
        TextBox6.Text = temp
        TextBox6.Enabled = False
        checkwin()
    End If
End Sub
Private Sub TextBox7_Click(sender As Object, e As EventArgs) Handles TextBox7.Click
    If ch = 1 Then
        temp2 = "sq7"
        checkcount()
        TextBox7.Text = temp
        TextBox7.Enabled = False
        checkwin()
    End If
End Sub
Private Sub TextBox8_Click(sender As Object, e As EventArgs) Handles TextBox8.Click
    If ch = 1 Then
        temp2 = "sq8"
        checkcount()
        TextBox8.Text = temp
        TextBox8.Enabled = False
        checkwin()
    End If
End Sub
Private Sub TextBox9_Click(sender As Object, e As EventArgs) Handles TextBox9.Click
    If ch = 1 Then
        temp2 = "sq9"
        checkcount()
        TextBox9.Text = temp
        TextBox9.Enabled = False
        checkwin()
    End If
End Sub
'this repeats 9 for a total 81 textbox's 

为什么 if 运行良好,而else返回这个烦人的注释:取消链接(../ media / books /)[function.unlink]:是一个目录(路径。 ..)

我希望别人什么都不做。

2 个答案:

答案 0 :(得分:1)

您的变量$oldcover似乎为空。您还可以更改条件以检查文件是否存在以及它不是目录。

if(file_exists("../media/books/$oldcover") && !is_dir("../media/books/$oldcover"))

答案 1 :(得分:1)

听起来你的$oldcover变量可能为空,因此检查目录是否存在。

然后尝试unlink目录。也许你应该试试这个:

if($oldcover && file_exists("../media/books/$oldcover")) {
  unlink("../media/books/$oldcover");
} else { 
  //do nothing 
}