在运行项目时,并非所有form_load代码都运行

时间:2021-09-26 13:57:59

this code was just working! but for some reason it stopped to work now. when i run this project the following code is supposed to execute but it does not! please help.

这段代码刚刚起作用!但由于某种原因,它现在停止工作了。当我运行这个项目时,下面的代码应该执行,但它不会!请帮忙。

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

1 个解决方案

#1


Its diffiuclt to be able to say for certain what is wrong since you've only posted the Form1_Load method. You also need to be a bit more explicit in your question; does the method execute at all? Have you tried to set a break point with the debugger and step through the method?

由于您只发布了Form1_Load方法,因此可以确定是什么问题。您还需要在问题中更明确一些;该方法是否完全执行?您是否尝试使用调试器设置断点并逐步执行该方法?

You may also want to wrap your code in an try catch block to see if your code is throwing an exception. So your code would be:

您可能还希望将代码包装在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

I think the problem may just be with your XML document however so you may want to check that too.

我认为问题可能只与您的XML文档有关,因此您可能也想检查它。

#1


Its diffiuclt to be able to say for certain what is wrong since you've only posted the Form1_Load method. You also need to be a bit more explicit in your question; does the method execute at all? Have you tried to set a break point with the debugger and step through the method?

由于您只发布了Form1_Load方法,因此可以确定是什么问题。您还需要在问题中更明确一些;该方法是否完全执行?您是否尝试使用调试器设置断点并逐步执行该方法?

You may also want to wrap your code in an try catch block to see if your code is throwing an exception. So your code would be:

您可能还希望将代码包装在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

I think the problem may just be with your XML document however so you may want to check that too.

我认为问题可能只与您的XML文档有关,因此您可能也想检查它。