2017-10-07 73 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 
相关问题