2017-10-07 59 views
0

我在將文本從文本框保存到文件時遇到問題。VB.NET從文本框保存數據

代碼>

If Not File.Exists(My.Application.Info.DirectoryPath() + "\httpd\conf\httpd.conf") Then 
    Using sw As StreamWriter = New StreamWriter(My.Application.Info.DirectoryPath() + "\httpd\conf\httpd.conf", False) 
     sw.Write(httpdconf.Text & My.Application.Info.DirectoryPath() & "\httpd" & httpdconf2.Text & My.Application.Info.DirectoryPath() & "\www" & httpdconf3.Text & My.Application.Info.DirectoryPath() & "\www" & httpdconf4.Text & My.Application.Info.DirectoryPath & "\cgi-bin" + httpdconf5.Text & My.Application.Info.DirectoryPath & "\cgi-bin" & httpdconf6.Text) 
    End Using 

End If 

的問題是,該文本保存而不httpdconf.Text行程序認爲該文本是空的(即使不是)。即使是設計師看起來奇怪

例>

 ' 
     'httpdconf 
     ' 
     Me.httpdconf.Location = New System.Drawing.Point(10, 68) 
     Me.httpdconf.Name = "httpdconf" 
     Me.httpdconf.Size = New System.Drawing.Size(77, 102) 
     Me.httpdconf.TabIndex = 15 
     Me.httpdconf.Text = resources.GetString("httpdconf.Text") 

代替文本 - > resources.GetString( 「httpdconf.Text」)< -

我不與文本理解什麼需要。
(文本是預先指定的) - (文本不說用戶)

+0

程序的擁塞看起來你編輯的文件設計師自己。它包括警告不這樣做。如果文本是靜態的,爲什麼不能在表單加載中添加它?爲什麼把它放在一個文本框中,如果你想要寫出文本,用戶可以改變它?請閱讀[問]並參加[旅遊] – Plutonix

回答

0

固定 我把,我想保存到一個文件中的代碼,程序會從該文件中作出。究其原因>當您加載一個大文本推出後

代碼>

  Dim apache_1 
      Dim apache_2 
      Dim apache_3 
      Dim apache_4 
      Dim apache_5 
      Dim apache_6 
      Using sr1 As StreamReader = New StreamReader(My.Application.Info.DirectoryPath() + "\default_conf\apache_1") 
       apache_1 = sr1.ReadToEnd 
      End Using 
      Using sr2 As StreamReader = New StreamReader(My.Application.Info.DirectoryPath() + "\default_conf\apache_2") 
       apache_2 = sr2.ReadToEnd 
      End Using 
      Using sr3 As StreamReader = New StreamReader(My.Application.Info.DirectoryPath() + "\default_conf\apache_3") 
       apache_3 = sr3.ReadToEnd 
      End Using 
      Using sr4 As StreamReader = New StreamReader(My.Application.Info.DirectoryPath() + "\default_conf\apache_4") 
       apache_4 = sr4.ReadToEnd 
      End Using 
      Using sr5 As StreamReader = New StreamReader(My.Application.Info.DirectoryPath() + "\default_conf\apache_5") 
       apache_5 = sr5.ReadToEnd 
      End Using 
      Using sr6 As StreamReader = New StreamReader(My.Application.Info.DirectoryPath() + "\default_conf\apache_6") 
       apache_6 = sr6.ReadToEnd 
      End Using 



      Using sw As StreamWriter = New StreamWriter(My.Application.Info.DirectoryPath() + "\httpd\conf\httpd.conf", False) 
       sw.Write(apache_1 & My.Application.Info.DirectoryPath() & "\httpd" & apache_2 & My.Application.Info.DirectoryPath() & "\www" & apache_3 & My.Application.Info.DirectoryPath() & "\www" & apache_4 & My.Application.Info.DirectoryPath & "\cgi-bin" + apache_5 & My.Application.Info.DirectoryPath & "\cgi-bin" & apache_6) 
      End Using 
相關問題