vb.net保存到txt的简单介绍

50分 vb.net 如何保存文本框内容到txt文件

窗体上建立BUTTON1和TEXTBOX1

让客户满意是我们工作的目标,不断超越客户的期望值来自于我们对这个行业的热爱。我们立志把好的技术通过有效、简单的方式提供给客户,将通过不懈努力成为客户在信息化领域值得信任、有价值的长期合作伙伴,公司提供的服务项目有:主机域名、网页空间、营销软件、网站建设、大宁网站维护、网站推广。

代码如下

100%正确,刚刚写的,调试好了

Imports System.io

Public Class form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim fs As New FileStream("d:\文本.txt", FileMode.Create, FileAccess.Write)

Dim r As New StreamWriter(fs)

Dim I As Integer

r.Write(TextBox1.Lines(I))

r.Flush()

r.Close()

End Sub

End Class

路径自己修改

(你的给分是我回答的动力)

vb.net 中 datagridview的数据如何保存到 txt

Dim i As Integer

Dim j As Integer

Dim myFile As New System.IO.StreamWriter("c:\Test.txt")

Dim strTemp As String = ""

For j = 0 To frmQuery.DataGridView1.RowCount - 1

strTemp = ""

For i = 0 To frmQuery.DataGridView1.Columns.Count - 1

strTemp = "'" frmQuery.DataGridView1(i, j).Value "'" ","

Next

myFile.WriteLine(strTemp)

Next

myFile.Close()

格式为表格每行保存为文本文件的一行,字段之间以逗号分隔。

求VB.NET写的自动保存txt文档的代码

直接给你保存和读取TXT的VB.NET的函数代码,你只要在触发事件中调用就可以了,注意换行,有的是显示不下去才显示两行的,还有strFilePath代表文件路径,TempENG代表文件编码格式如:UTF-8或者GB2312,strText 代表内容字符串。

#Region "读取TXT"

Public Function ReadTxt(ByVal strFilePath As String, ByVal TempENG As String) As String

Dim mySr As System.IO.StreamReader

Dim strS As String

Dim n%

strS = ""

mySr = New System.IO.StreamReader(strFilePath, System.Text.Encoding.GetEncoding(TempENG))

Do

Dim line$ = mySr.ReadLine()

strS = strS line vbCrLf

n = n + 1

Loop Until mySr.EndOfStream = True

mySr.Close()

Return strS

End Function

#End Region

#Region "保存TXT"

Public Function SaveTxt(ByVal strFilePath As String, ByVal strText As String, ByVal TempENG As String) As Boolean

Try

If Dir(strFilePath) "" Then File.Delete(strFilePath)

Dim mySw As System.IO.StreamWriter

Dim strLine() As String

mySw = New System.IO.StreamWriter(strFilePath, True, System.Text.Encoding.GetEncoding(TempENG))

strLine = Split(strText, vbCrLf)

For i As Integer = 0 To UBound(strLine)

mySw.WriteLine(strLine(i))

Next

mySw.Close()

Return True

Catch ex As Exception

Return False

End Try

End Function

#End Region


当前文章:vb.net保存到txt的简单介绍
链接分享:http://csdahua.cn/article/doipphd.html
扫二维码与项目经理沟通

我们在微信上24小时期待你的声音

解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流