0

切入正题:

Function Create(ByVal network, ByVal location, ByVal type, ByVal requirement1, ByVal requirement2, ByVal requirement3, ByVal name)
    Dim net As String = network
    Dim loc As String = location
    Dim typ As String = type
    Dim nam As String = name
    Dim req1 As String = requirement1
    Dim req2 As String = requirement2
    Dim req3 As String = requirement3
    Dim Mission As New System.IO.StreamWriter("C:\" & nam & ".txt")
    Mission.WriteLine("Name: " & net)
    Mission.WriteLine("Network: " & net)
    Mission.WriteLine("Location: " & loc)
    Mission.WriteLine("Type: " & typ)
    Mission.WriteLine("Requirement: " & req1)
    Mission.WriteLine("Requirement: " & req2)
    Mission.WriteLine("Requirement: " & req3)
    Mission.Close()
    Console.WriteLine("Written")
    System.Threading.Thread.Sleep(3000)
End Function

没有出现错误,但文件路径中的文件也没有出现。我在调用函数时已经声明了所有内容,所以我知道这不是问题所在。帮助?:)

4

1 回答 1

0
Sub Create(ByVal network As String, ByVal location As String, 
    ByVal type As String, ByVal requirement1 As String, 
    ByVal requirement2 As String, ByVal requirement3 As String,
    ByVal name As String)

    Dim net As String = network
    Dim loc As String = location
    Dim typ As String = type
    Dim nam As String = name
    Dim req1 As String = requirement1
    Dim req2 As String = requirement2
    Dim req3 As String = requirement3
    If Not nam.EndsWith(".txt") Then
        nam &= ".txt"
    End If
    Dim Mission As New System.IO.StreamWriter(Path.Combine(
      System.Environment.GetFolderPath(
      System.Environment.SpecialFolder.Desktop), nam))
    Mission.WriteLine("Name: " & net)
    Mission.WriteLine("Network: " & net)
    Mission.WriteLine("Location: " & loc)
    Mission.WriteLine("Type: " & typ)
    Mission.WriteLine("Requirement: " & req1)
    Mission.WriteLine("Requirement: " & req2)
    Mission.WriteLine("Requirement: " & req3)
    Mission.Close()
    Console.WriteLine("Written")
    'System.Threading.Thread.Sleep(3000)
End Sub

首先,朋友,您将参数作为对象传递!!,其次,除非您具有管理员权限,否则您无权保存到 c 根目录,第三,最后的线程部分完全没用,它会阻塞 UI,不要'没有任何好处。
最后但并非不重要。
祝你好运

于 2012-08-27T05:52:16.880 回答