0

我在下面的代码中没有收到任何语法错误,但是当我编译代码时,我得到了 Msgbox("cant post status") 而不是 main.p(x).status(0) 的输出。x 和 0 可以是任何数字,我总是得到无法发布状态框。最让我烦恼的是,我有一个带有richtextbox 的调试表单,我将所有七次出现的数组中的所有数据:p 加载到程序启动时,它工作得很好。我也在最底部包含了该代码。在运行日志记录子程序之前,我运行了一个初始化子程序,它将默认值放入每个变量中。当我在 main_loop 中没有 try/catch 时,我不会收到错误,但所有执行都会停止。我的电脑没有死机,但是应该在那个子之后发生的动作没有。有谁知道为什么我不能调用 main.p(x)。

    'Main Class'
    Public p(6) as structs.player

    Public Shared Sub main_loop()
        For x As Integer = 0 To (Main.p.Count - 1) Step 1
            If Main.check_act(x) = False Then
                MsgBox("past check act")
                If Main.p(x).pos >= 1 And Main.p(x).pos <= 3 Then
                    MsgBox("past pos; pre death")
                    Try
                        MsgBox(Main.p(x).status(0))
                    Catch ex As Exception
                        MsgBox("cant post status")
                        End
                    End Try
                End If
            End If
        Next
    End Sub

    'Structs Class'
    Public Structure player

        Dim name As String
        Dim type As String
        Dim pos As Integer
        Dim wait As Integer

        Dim mhp As Integer
        Dim chp As Integer
        Dim mmp As Integer
        Dim cmp As Integer
        Dim map As Integer
        Dim cap As Integer

        Dim atk As Integer
        Dim def As Integer
        Dim mak As Integer
        Dim mdf As Integer
        Dim spd As Integer
        Dim acc As Integer
        Dim eva As Integer
        Dim crt As Integer

        Dim status() As Integer
        Dim stats() As Integer
        Dim statr() As Integer
        Dim elems() As Integer
        Dim elemr() As Integer

        Dim abl() As Boolean

    End Structure


    'Debug Class'
    Public Shared Sub log(p As player)

        'Stats'
        Debug.log.Text += ">>> " & p.name.ToString & " <<<" & Chr(10)
        Debug.log.Text += "Type: " & p.type.ToString & Chr(10)
        Debug.log.Text += "Pos: " & p.pos.ToString & Chr(10)
        Debug.log.Text += "Wait: " & p.wait.ToString & Chr(10) & Chr(10)

        Debug.log.Text += "HP: " & p.mhp.ToString & _
            "/" & p.chp.ToString & Chr(10)
        Debug.log.Text += "MP: " & p.mmp.ToString & _
            "/" & p.cmp.ToString & Chr(10)
        Debug.log.Text += "AP: " & p.map.ToString & _
            "/" & p.cap.ToString & Chr(10) & Chr(10)

        Debug.log.Text += "ATK: " & p.atk.ToString & Chr(10)
        Debug.log.Text += "DEF: " & p.def.ToString & Chr(10)
        Debug.log.Text += "MAK: " & p.mak.ToString & Chr(10)
        Debug.log.Text += "MDF: " & p.mdf.ToString & Chr(10)
        Debug.log.Text += "SPD: " & p.spd.ToString & Chr(10)
        Debug.log.Text += "ACC: " & p.acc.ToString & Chr(10)
        Debug.log.Text += "EVA: " & p.eva.ToString & Chr(10)
        Debug.log.Text += "CRT: " & p.crt.ToString & Chr(10) & Chr(10)

        'Status And Elements'
        For x As Integer = 0 To (p.status.Count - 1) Step 1
            Debug.log.Text += p.status(x).ToString & Chr(10)
        Next
        Debug.log.Text += Chr(10)
        For x As Integer = 0 To (p.stats.Count - 1) Step 1
            Debug.log.Text += p.stats(x).ToString & Chr(10)
        Next
        Debug.log.Text += Chr(10)
        For x As Integer = 0 To (p.statr.Count - 1) Step 1
            Debug.log.Text += p.statr(x).ToString & Chr(10)
        Next
        Debug.log.Text += Chr(10)
        For x As Integer = 0 To (p.elems.Count - 1) Step 1
            Debug.log.Text += p.elems(x).ToString & Chr(10)
        Next
        Debug.log.Text += Chr(10)
        For x As Integer = 0 To (p.elemr.Count - 1) Step 1
            Debug.log.Text += p.elemr(x).ToString & Chr(10)
        Next
        Debug.log.Text += Chr(10)

        'Abilities'
        For x As Integer = 0 To (p.abl.Count - 1) Step 1
            Debug.log.Text += p.abl(x).ToString & Chr(10)
        Next
        Debug.log.Text += Chr(10)

    End Sub
4

1 回答 1

0

我快速调试了代码并确定 status(0) 是问题所在。
以下屏幕图像显示错误...

在此处输入图像描述

于 2013-10-09T14:05:01.857 回答