vb如何向文本文件中添加内容
答案:3 悬赏:40 手机版
解决时间 2021-11-22 16:54
- 提问者网友:最美的风景
- 2021-11-22 07:04
vb如何向文本文件中添加内容
最佳答案
- 五星知识达人网友:狂恋
- 2021-11-22 07:33
写文件采用追加模式即可:实例代码如下:
Dim i As Integer, n As Integer, a(6) As Integer
n = 6
Open "D:1122.txt" For Append As #1
Randomize
For i = 1 To n
a(i) = Int(Rnd * 1000 + 1)
Print #1, a(i)
Next i
Close #1
Dim i As Integer, n As Integer, a(6) As Integer
n = 6
Open "D:1122.txt" For Append As #1
Randomize
For i = 1 To n
a(i) = Int(Rnd * 1000 + 1)
Print #1, a(i)
Next i
Close #1
全部回答
- 1楼网友:纵马山川剑自提
- 2021-11-22 09:12
cmd1的单击代码
——————————————————————————————————
open "(这里输入name.txt的完整路径,比如c:\windows\name.txt,引号别漏了,括号不要)" for output as #1 '打开name.text如果已经存在,那么就用新的替换旧的,假如你不想替换而希望在文本末继续写,那就把for output改成for Append
print #1,text1.text 'text1的内容加入到name.text中
close #1 '关闭name.text,说白点就是保存啦
——————————————————————————————————
cmd2的单击代码
——————————————————————————————————
open "(这里输入name.txt的完整路径,比如c:\windows\name.txt,引号别漏了,括号不要)" for output as #2
close #2 '删除?那就什么也不输入,就是空白的了
——————————————————————————————————
——————————————————————————————————
open "(这里输入name.txt的完整路径,比如c:\windows\name.txt,引号别漏了,括号不要)" for output as #1 '打开name.text如果已经存在,那么就用新的替换旧的,假如你不想替换而希望在文本末继续写,那就把for output改成for Append
print #1,text1.text 'text1的内容加入到name.text中
close #1 '关闭name.text,说白点就是保存啦
——————————————————————————————————
cmd2的单击代码
——————————————————————————————————
open "(这里输入name.txt的完整路径,比如c:\windows\name.txt,引号别漏了,括号不要)" for output as #2
close #2 '删除?那就什么也不输入,就是空白的了
——————————————————————————————————
- 2楼网友:山有枢
- 2021-11-22 08:20
Private Sub Command1_Click()
Open App.Path & "\name.txt" For Append As #1
Print #1, Text1
Close #1
End Sub
Private Sub Command2_Click()
Dim s As String
Open App.Path & "\name.txt" For Input As #1
s = StrConv(InputB$(LOF(1), #1), vbUnicode)
Close #1
s = Replace(s, Text1, "")
Open App.Path & "\name.txt" For Output As #1
Print #1, s
Close #1
End Sub
Open App.Path & "\name.txt" For Append As #1
Print #1, Text1
Close #1
End Sub
Private Sub Command2_Click()
Dim s As String
Open App.Path & "\name.txt" For Input As #1
s = StrConv(InputB$(LOF(1), #1), vbUnicode)
Close #1
s = Replace(s, Text1, "")
Open App.Path & "\name.txt" For Output As #1
Print #1, s
Close #1
End Sub
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯