2013-10-09 81 views
0

我在下面的代碼中沒有得到任何語法錯誤,但是當我編譯代碼時,我得到了Msgbox(「cant post status」)而不是main.p(x).status(0)的輸出。 x和0可以是任何數字,我總是能看到帖子狀態框。最讓我感到困擾的是我有一個帶有richtextbox的調試表單,我將所有七次出現數據的所有數據加載到程序啓動時的p中,並且它工作得很好。我已經在最底層包含了該代碼。在運行logging sub之前,我運行了一個初始化子程序,它將默認值放入每個變量中。當我在main_loop中沒有try/catch時,我沒有收到錯誤,但是所有的執行都停止了。我的電腦沒有凍結,但是在該分區之後應該進行的操作不會。有誰知道爲什麼我不能打電話給這個子內的main.p(x).status(0)?VB.Net正確的代碼不起作用?

'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 
+0

如果你把一個斷點上MSGBOX(無法發送郵件)線和看前會發生什麼? – peterG

+0

@ zever你有沒有把任何東西放在'status'來顯示? – Plutonix

+0

你必須看看異常,而不是僅僅返回messagebox'「無法發佈狀態''將其替換爲'MsgBox(」不能發佈狀態,因爲「+ ex.Message)' – SSpoke

回答

0

我快速調試代碼確定狀態(0)是問題。
下面的屏幕圖像顯示了錯誤...

enter image description here

+0

我不確定你是如何得到這些的,但我知道這是不對的。在我遇到「錯誤」之前,我會將數據輸出到另一個表單上的richtectbox。我如何能夠儘早輸出數據,但以後不能參考? – ZeverMX

+0

也許您可以在以下行上設置斷點: 「MsgBox(Main.p(x).status(0))」 ...然後檢查p(x).status(0)的內容 – Seymour

+0

我從來沒有使用過斷點,所以我可能會做錯,但我沒有收到任何錯誤或任何其他事情,除非它停止執行。我無法看到p(x).status(0)的內容是什麼。 – ZeverMX