在调试期间不会破坏代码的错误

时间:2014-01-27 21:53:31

标签: vb.net debugging visual-studio-2012

我正在制作一款游戏,允许用户选择多个日文字符(平假名,片假名和汉字),然后测试他们对角色发音的了解。

这是通过从SQL数据库中获取字符,将它们添加到一个数组然后转换为CSV文件来实现的。

然后在用户开始玩游戏时检索此文件。

我用来将SQL数据库中的字符带入游戏的代码可以正常工作,因为我能够使用Msgbox()显示数组中的项目。

不幸的是,当我开始执行游戏时(单击游戏表单上的开始按钮,而不是启动程序),程序冻结并且不接受来自鼠标或键盘的任何输入。当我关闭程序时,它会在调试菜单中返回以下信息:

这会有点垃圾邮件,所以我提前道歉

'KES.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_32\mscorlib\v4.0_4.0.0.0__b77a5c561934e089\mscorlib.dll'
'KES.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\assembly\GAC_MSIL\Microsoft.VisualStudio.HostingProcess.Utilities\11.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.HostingProcess.Utilities.dll'
'KES.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Windows.Forms\v4.0_4.0.0.0__b77a5c561934e089\System.Windows.Forms.dll'
'KES.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Drawing\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Drawing.dll'
'KES.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System\v4.0_4.0.0.0__b77a5c561934e089\System.dll'
'KES.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\assembly\GAC_MSIL\Microsoft.VisualStudio.HostingProcess.Utilities.Sync\11.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.HostingProcess.Utilities.Sync.dll'
'KES.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\assembly\GAC_MSIL\Microsoft.VisualStudio.Debugger.Runtime\11.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.Debugger.Runtime.dll'
'KES.vshost.exe' (Managed (v4.0.30319)): Loaded 'J:\Computing Coursework\real project\KES\KES\bin\Debug\KES.vshost.exe'
'KES.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_32\System.Data\v4.0_4.0.0.0__b77a5c561934e089\System.Data.dll'
'KES.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Core\v4.0_4.0.0.0__b77a5c561934e089\System.Core.dll'
'KES.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\assembly\GAC_MSIL\System.Data.SqlServerCe\4.0.0.0__89845dcd8080cc91\System.Data.SqlServerCe.dll'
'KES.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Deployment\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Deployment.dll'
'KES.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Xml\v4.0_4.0.0.0__b77a5c561934e089\System.Xml.dll'
'KES.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Xml.Linq\v4.0_4.0.0.0__b77a5c561934e089\System.Xml.Linq.dll'
'KES.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Data.DataSetExtensions\v4.0_4.0.0.0__b77a5c561934e089\System.Data.DataSetExtensions.dll'
'KES.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\Microsoft.VisualBasic\v4.0_10.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualBasic.dll'
The thread 'vshost.NotifyLoad' (0x1140) has exited with code 0 (0x0).
The thread 'vshost.LoadReference' (0x14a4) has exited with code 0 (0x0).
'KES.vshost.exe' (Managed (v4.0.30319)): Loaded 'J:\Computing Coursework\real project\KES\KES\bin\Debug\KES.exe', Symbols loaded.
'KES.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Runtime.Remoting\v4.0_4.0.0.0__b77a5c561934e089\System.Runtime.Remoting.dll'
'KES.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Configuration\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll'
'KES.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_32\System.Transactions\v4.0_4.0.0.0__b77a5c561934e089\System.Transactions.dll'
'KES.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_32\System.EnterpriseServices\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.EnterpriseServices.dll'
'KES.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_32\System.EnterpriseServices\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.EnterpriseServices.Wrapper.dll'
'KES.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Numerics\v4.0_4.0.0.0__b77a5c561934e089\System.Numerics.dll'
The program '[3316] KES.vshost.exe: Managed (v4.0.30319)' has exited with code -1 (0xffffffff).

这是调试的整个输出,似乎我的游戏代码没有产生任何语法错误,虽然我已经把它放在这里除了调试以便如果有任何问题,它们可以是发现(如果是代码的错误)。

Public Class UntimedMode
Dim dataArray(1, 239) As String
Dim arrayLength As Integer
Dim gameRunning As Boolean
Dim randomNumber As Integer
Dim score As Integer
Dim attempts As Integer
Dim attemptLimit As Integer = 2

Sub characterListLength(Optional ByVal optionalNumber As Integer = 0) 'This function checks the length of the array before the game starts
    Dim rowCount As Integer
    Dim endOfArray As Boolean
    While endOfArray = False
        If dataArray(0, rowCount) = "" And dataArray(1, rowCount) = "" Then
            arrayLength = rowCount - 1
            endOfArray = True
        Else
            rowCount += 1
        End If
    End While
End Sub

Sub randomise(Optional ByVal optionalNumber As Integer = 0)
    randomNumber = CInt(Int((arrayLength * Rnd()) + 1))
End Sub



Private Sub UntimedMode_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    Me.FormBorderStyle = FormBorderStyle.FixedSingle
    btn_Stop.Hide()
    btn_start.Show()

End Sub

Private Sub Button4_Click(sender As Object, e As EventArgs) Handles btn_quit.Click
    Tokyo.Show() 'displays the menu screen
    Me.Close()
End Sub

Private Sub btn_start_Click(sender As Object, e As EventArgs) Handles btn_start.Click
    gameRunning = True
    btn_start.Hide()
    btn_Stop.Show()
    Dim varFileName As String = "J:\Computing Coursework\real project\KES\Resources\csv.txt"


    Dim FileData As New System.IO.StreamReader(varFileName) 'This piece of code takes the csv file and turns it into an array. The data can now be called using Array(1,1) to get the first value

    Dim FileRows() As String = Split(FileData.ReadToEnd(), vbCrLf) 'Read in each row.
    Dim NumberOfRows As Long = FileRows.GetUpperBound(0) ' Count number of rows.

    Dim FileColumns() As String = FileRows(0).Split(","c) 'Split row 1 data in to columns.
    Dim NumberOfColumns As Long = FileColumns.GetUpperBound(0) ' Count number of columns.

    ReDim dataArray(NumberOfRows, NumberOfColumns) 'Declare the array correctly with new data

    For x = 0 To NumberOfRows 'Cycle through all the rows
        FileColumns = FileRows(x).Split(","c) 'Split row into columns
        For y = 0 To NumberOfColumns 'Now cycle through all the columns on that row
            Try
                dataArray(x, y) = FileColumns(y) 'Set each piece of data into the array. 
            Catch ex As Exception
            End Try
        Next
    Next

    FileData.Close()

    characterListLength() 'This function checks the length of the newly filled array so that an appropriate random index can be used

    While gameRunning = True 'Sets the gameRunning variable to True so that the code recognises the fact that the game is running
        randomise() 'Generate t
        txtbox_Character.Text = dataArray(0, randomNumber)
        If attempts > attemptLimit Then
            MsgBox("The correct pronunciation is " + dataArray(1, randomNumber) + "!")
            randomise()
        End If

    End While

End Sub

Private Sub btn_enter_Click(sender As Object, e As EventArgs) Handles btn_enter.Click
    If gameRunning = True Then
        If txtbox_syllableEntry.Text = dataArray(1, randomNumber) Then
            score += 100
            attempts = 0
            'display positive feedback
            randomise()
        ElseIf txtbox_syllableEntry.Text = "" Then
            MsgBox("Please tpye in the pronunciation of the character")

        ElseIf txtbox_syllableEntry.Text <> "" And txtbox_syllableEntry.Text <> dataArray(1, randomNumber) Then

            score -= 75
            attempts += 1
            'display negative feedback
        End If


    End If
End Sub

Private Sub btn_Stop_Click(sender As Object, e As EventArgs) Handles btn_Stop.Click
    gameRunning = False
End Sub

结束班

不幸的是,我不知道问题出在哪里,虽然我觉得它可能与将日文字符加载到程序中有关,因为我已经看到在调试窗口中提到'符号'之前。任何有关此问题的帮助都非常有用。

0 个答案:

没有答案