我试图在VB.NET为一个学校项目建立一个囚徒困境游戏,我发现这个奇怪的行为我不明白。
我有两个按钮供播放器使用,“合作”和“缺陷”都有相同的代码结构:
Private Sub btnDefect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDefect.Click
Oponent()
MovePlayer = "Defect"
If MoveOponent = "Coop" Then
scorePlayer += 50
scoreOponent -= 50
Else
If MoveOponent = "Defect" Then
scorePlayer -= 10
scoreOponent -= 10
End If
End If
scores()
End Sub我知道其他-如果是不必要的,但我这样写它是为了更清楚和更易读。问题是,如果两个按钮都有其他按钮--如果我得到一个编译错误,并且无法从Visual运行游戏(不过,bin文件夹中的.exe工作正常)。现在,如果我从中移除ELSE -如果从按钮中删除,并且只保留一个普通的,它就会完美地工作。但是,如果我将其从这两种情况中删除,则会发生相同的错误。
我得到的错误是:
无法复制"obj\x86\Debug\PrisonersDilemma.exe“文件,因为找不到它。PrisonersDilemma
但是我找了那个.exe文件,它就在那里!
知道为什么会这样吗?我只留下一个-如果,但我想知道出了什么问题。
以下是供参考的完整代码:
Public Class Form1
Dim MovePlayer As String
Dim MoveOponent As String
Dim scorePlayer As Integer
Dim scoreOponent As Integer
Sub scores()
lblscoreOponent.Text = scoreOponent
lblscorePlayer.Text = scorePlayer
End Sub
Sub Oponent()
If MovePlayer = "" Then
MoveOponent = "Coop"
Else
MoveOponent = MovePlayer
End If
lblMoveOponent.Text = MoveOponent
lblMoveOponent.Visible = True
End Sub
Private Sub btnCoop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCoop.Click
Oponent()
MovePlayer = "Coop"
If MoveOponent = "Coop" Then
scorePlayer += 10
scoreOponent += 10
Else
scorePlayer += 50
scoreOponent -= 50
End If
scores()
End Sub
Private Sub btnDefect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDefect.Click
Oponent()
MovePlayer = "Defect"
If MoveOponent = "Coop" Then
scorePlayer += 50
scoreOponent -= 50
Else
If MoveOponent = "Defect" Then
scorePlayer -= 10
scoreOponent -= 10
End If
End If
scores()
End Sub
End Class谢谢!!
发布于 2013-10-22 14:17:08
1:编译时,如果出现错误,则不会替换bin文件夹中的EXE。您的EXE是最后一个成功的构建,这就是为什么您会遇到这样的问题:“在构建过程中出现了一个错误,您想要运行最后一个成功的构建吗?”如果你说是,这会运行EXE。
他说:我好像在2012年的时候见过“找不到”的错误,我认为这是Visual的一个问题。通常我再试一次,很好。如果从bin文件夹运行EXE,请在编译之前确保它没有运行。它将阻止复制它的能力。
他说:如果你想要帮助弄清楚为什么你得到了复合错误,你必须显示代码,而不是工作的代码!
https://stackoverflow.com/questions/19508451
复制相似问题