vb问题 文本文档写入

office_2007 2009-06-25 10:13:56
怎样 winform窗体上用循环for方法电脑系统的文本文档.txt里写入呢
...全文
36 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
xinnianle 2009-06-26
  • 打赏
  • 举报
回复
你是说Txt文本的循环写入操作?
你看着是不是你想要的
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim b As New IO.StreamWriter("C:\Users\LP\Desktop\111.txt", True, System.Text.Encoding.Default) 'True是追加False是覆盖
For i As Integer = 1 To 100 '循环100遍
b.WriteLine(String.Format("这是第{0}行字符串", i)) '写入Txt文本
Next
b.Close() '操作完毕关闭记事本
MsgBox("写入完毕", 64)
End Sub
office_2007 2009-06-25
  • 打赏
  • 举报
回复

Class Test
Public Shared Sub Main()
这个是什么方法里的?
kitome 2009-06-25
  • 打赏
  • 举报
回复
Imports System
Imports System.IO

Class Test
Public Shared Sub Main()
' Create an instance of StreamWriter to write text to a file.
Using sw As StreamWriter = New StreamWriter("TestFile.txt")
' Add some text to the file.
sw.Write("This is the ")
sw.WriteLine("header for the file.")
sw.WriteLine("-------------------")
' Arbitrary objects can also be written to the file.
sw.Write("The date is: ")
sw.WriteLine(DateTime.Now)
sw.Close()
End Using
End Sub
End Class
weilu0328 2009-06-25
  • 打赏
  • 举报
回复
LZ 这个应该是比较简单的吧!
fileStream = New FileStream(strFileName, System.IO.FileMode.CreateNew, System.IO.FileAccess.Write)
streamWriter = New StreamWriter(fileStream, System.Text.Encoding.Default)
streamWriter.WriteLine(strDocumentHeader)
office_2007 2009-06-25
  • 打赏
  • 举报
回复
看不明白了。 能不能2给出过程实例呢
CloneCenter 2009-06-25
  • 打赏
  • 举报
回复

16,554

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧