使用vb修改TXT内容
现有一个txt文件。其每行内容如下:第一行:…………(未知且非空)第二行:…………(未知且非空)第三行:3第四行:4第五行:5第六行:…………(未知且非空)……现在我想利...
现有一个txt文件。其每行内容如下:
第一行:…………(未知且非空)
第二行:…………(未知且非空)
第三行:3
第四行:4
第五行:5
第六行:…………(未知且非空)
……
现在我想利用vb完成如下操作:
将第一至第三行内容分别赋值给变量a,b,c
然后再不改变其他内容的状态下将第三行内容变为517138271
若能解决,小弟必另有悬赏分敬上!
eagleboycn的做法会使文档第三行以下内容消失!
需要更多回答! 展开
第一行:…………(未知且非空)
第二行:…………(未知且非空)
第三行:3
第四行:4
第五行:5
第六行:…………(未知且非空)
……
现在我想利用vb完成如下操作:
将第一至第三行内容分别赋值给变量a,b,c
然后再不改变其他内容的状态下将第三行内容变为517138271
若能解决,小弟必另有悬赏分敬上!
eagleboycn的做法会使文档第三行以下内容消失!
需要更多回答! 展开
3个回答
展开全部
fdir为文件目录+文件名
Open fdir For Input As #1 '打开fdir文件读
Line Input #1, a
Line Input #1, b
Line Input #1, c
Close #1
=======================
c=cstr(517138271) '改内容
=======================
Open fdir For output As #1 '打开fdir文件写
print #1, a
print #1, b
print #1, c
Close #1
Open fdir For Input As #1 '打开fdir文件读
Line Input #1, a
Line Input #1, b
Line Input #1, c
Close #1
=======================
c=cstr(517138271) '改内容
=======================
Open fdir For output As #1 '打开fdir文件写
print #1, a
print #1, b
print #1, c
Close #1
展开全部
Option Base 1
Private Sub Form_Click()
Dim m(), i, a, b, c
fn = FreeFile
Open "C:\Documents and Settings\kekecat\桌面\1.txt" For Input As fn
Do While Not EOF(fn)
Line Input #fn, x
i = i + 1
ReDim Preserve m(i)
m(i) = x
Loop
Close #fn
a = m(1): b = m(2): c = m(3)
Print a, b, c
fm = FreeFile
Open "C:\Documents and Settings\kekecat\桌面\1.txt" For Output As fm
For i = LBound(m) To UBound(m)
If i = 3 Then
Print #fm, "517138271"
Else
Print #fm, m(i)
End If
Next
Close #fm
End Sub
Private Sub Form_Click()
Dim m(), i, a, b, c
fn = FreeFile
Open "C:\Documents and Settings\kekecat\桌面\1.txt" For Input As fn
Do While Not EOF(fn)
Line Input #fn, x
i = i + 1
ReDim Preserve m(i)
m(i) = x
Loop
Close #fn
a = m(1): b = m(2): c = m(3)
Print a, b, c
fm = FreeFile
Open "C:\Documents and Settings\kekecat\桌面\1.txt" For Output As fm
For i = LBound(m) To UBound(m)
If i = 3 Then
Print #fm, "517138271"
Else
Print #fm, m(i)
End If
Next
Close #fm
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Dim l As Integer
Dim n()
Private Sub Command2_Click()
a = n(1)
b = n(2)
c = n(3)
Print a;
Print b;
Print c;
n(3) = "517138271"
Open App.Path & "\11.txt" For Output As #1
For ii = 1 To UBound(n)
Print #1, n(ii)
Next ii
Close #1
End Sub
Private Sub Command3_Click()
Open App.Path & "\11.txt" For Input As #1
Do While Not EOF(1)
l = l + 1 '可以得到行数
ReDim Preserve n(l)
Line Input #1, n(l)
Loop
Close #1
End Sub
Dim n()
Private Sub Command2_Click()
a = n(1)
b = n(2)
c = n(3)
Print a;
Print b;
Print c;
n(3) = "517138271"
Open App.Path & "\11.txt" For Output As #1
For ii = 1 To UBound(n)
Print #1, n(ii)
Next ii
Close #1
End Sub
Private Sub Command3_Click()
Open App.Path & "\11.txt" For Input As #1
Do While Not EOF(1)
l = l + 1 '可以得到行数
ReDim Preserve n(l)
Line Input #1, n(l)
Loop
Close #1
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询