2009-06-10 103 views
-1

這個代碼只是工作!但由於某種原因,它現在停止了工作。當我運行這個項目時,下面的代碼應該執行,但它不會!請幫忙。,不是所有的Form_Load代碼運行

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 
    Dim xmldoc As New System.Xml.XmlDocument() 

    'Load from file 

    xmldoc.Load("http://sites.google.com/site/shadchanproject/Home/lots1.xml") 

    'Get a list of all the child elements 

    Dim nodelist As XmlNodeList = xmldoc.DocumentElement.ChildNodes 

    'Parse through all nodes 

    For Each outerNode As XmlNode In nodelist 

     ListBox1.Items.Add(outerNode.Name) 
    Next 
End Sub 
+0

是Form_Load事件還是有線的? – 2009-06-10 05:54:44

+0

是什麼問題?你的意思是什麼不執行?是xmldoc能夠從url加載xml嗎? – shahkalpesh 2009-06-10 05:55:41

回答

1

它的diffiuclt能夠肯定地說出了什麼是錯的,因爲你只發布了Form1_Load方法。你也需要在你的問題上更加明確一些;該方法是否可以執行?你有沒有試圖用調試器設置一個斷點並逐步完成該方法?

您可能還需要包裝在try catch塊你的代碼,看看你的代碼拋出異常。所以你的代碼將是:

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 

     Dim xmldoc As New System.Xml.XmlDocument() 

     Try 
      'Load from file 
      xmldoc.Load("http://sites.google.com/site/shadchanproject/Home/lots1.xml") 
     Catch ex As Exception 
      MessageBox.Show(ex.Message, "Problem loading the document") 
     End Try 

     Try 
      'Get a list of all the child elements 
      Dim nodelist As XmlNodeList = xmldoc.DocumentElement.ChildNodes 

      'Parse through all nodes 
      For Each outerNode As XmlNode In nodelist 

       ListBox1.Items.Add(outerNode.Name) 
      Next 
     Catch ex As Exception 
      MessageBox.Show(ex.Message, "Problem with the nodes.") 

     End Try 
    End Sub 

我認爲這個問題可能只是與你的XML文件,但你可能也想檢查。