繁体   English   中英

VB.NET从文本框中保存数据

[英]VB.NET Save data from textbox

我在将文本从TextBox保存到文件时遇到麻烦。

代码>

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”)<-

我不理解本文的内容。
(文本是预先指定的)-(文本不说用户)

已修正,我将要保存的代码保存到文件中,该程序将从该文件中获取。 原因>启动后加载大文本时程序拥塞

代码>

            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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM