0
   Function getItems()
        ''# make a reference to a directory
        Dim di As New IO.DirectoryInfo("https://ipossum.svn.sourceforge.net/svnroot/ipossum/")
        Dim diar1 As IO.FileInfo() = di.GetFiles()
        Dim dra As IO.FileInfo

        ''#list the names of all files in the specified directory
        For Each dra In diar1
            ListBox1.Items.Add(dra)
        Next
    End Function

那是我的代码,它不起作用。错误是“ Warning 1 Function 'getItems' doesn't return a value on all code paths. A null reference exception could occur at run time when the result is used. C:\Users\******\AppData\Local\Temporary Projects\iPossum\Form1.vb 13 5 iPossum”。

我该怎么做呢?谢谢!

4

1 回答 1

2

要修复您询问的错误,只需将单词更改FunctionSub.

但是,执行此操作后,您的代码仍然无法工作。您将遇到一个新错误,因为System.IO 目录和文件类仅适用于本地文件系统。您不能以这种方式引用远程 https 位置。您将需要改用 System.Net.HttpWebRequest/System.Net.HttpWebResponse 或 System.Net.WebClient,这意味着从头开始使用此代码。


一个非常简单的示例,可能会也可能不会,具体取决于 https 要求:

Dim fileList As String
Using wc As New WebClient
    fileList = wc.DownloadString("https://ipossum.svn.sourceforge.net/svnroot/ipossum/")
End Using
''# Here you'll have to parse the file names out of this response on your own
于 2010-08-04T21:30:42.897 回答