2012-08-26 60 views
0

切割保存.txt文件在vb.net題:

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 

沒有出現任何錯誤,但同樣沒有在文件路徑的文件。當我調用函數時,我已經聲明瞭所有的聲明,所以我知道它不是問題。 幫助? :)

+0

用調試器逐步完成。看起來像你壓抑或失去一個例外。 –

+0

沒什麼了。 –

+0

我已經導入了所有必要的系統。 –

回答

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盤根目錄下,除非你有管理員權限,第三末尾的螺紋部完全無用的,它阻止用戶界面,並沒有加起來任何好處。最後但並非最不重要的是

祝你好運

+0

感謝朋友,明白了。線程部分是我在退出控制檯之前可以看到它正在寫入文件。 –