vb的一个问题。。求解答 50
创建一个command1和command2然后点击command1载入文本文本格式如下:20070401-0576885320070401-056686562007040...
创建一个command1和command2
然后点击command1载入文本
文本格式如下:
20070401-057 68853
20070401-056 68656
20070401-055 02237
20070401-054 83184
20070401-053 17037
20070401-052 54896
20070401-051 25450
20070401-050 80138
20070401-049 07955
20070401-048 63505
20070401-047 64716
要求的是把除了每行最后的5个数字以外的全部去掉
然后点击command2 保存为txt文本
如图: 展开
然后点击command1载入文本
文本格式如下:
20070401-057 68853
20070401-056 68656
20070401-055 02237
20070401-054 83184
20070401-053 17037
20070401-052 54896
20070401-051 25450
20070401-050 80138
20070401-049 07955
20070401-048 63505
20070401-047 64716
要求的是把除了每行最后的5个数字以外的全部去掉
然后点击command2 保存为txt文本
如图: 展开
4个回答
展开全部
’如果不按照你的要求来写,确实可以很简单,一个过程就可以解决,或是一边读一边写都可以
下边代码是按照你的要求分开实现的。
Dim st As String '目标内容
Dim FileName As String '文件名
'读取
Private Sub Command1_Click()
FileName = InputBox("请输入文件全名", , "c:\1.TXT")
st = Deal(FileName)
Print st
End Sub
'保存
Private Sub Command2_Click()
Dim fn As String
fn = InputBox("请输入文件全名", , FileName)
Open fn For Output As #112 '输出
Print #112, st
Close #112
End Sub
'处理函数
Private Function Deal(FileName As String) As String
If FileName = "" Then Exit Function
Dim s As String
Open FileName For Input As #112
While Not EOF(112)
Line Input #112, s
If s <> "" Then Deal = Deal & Right(s, 5) & vbNewLine
Wend
Close #112
End Function
下边代码是按照你的要求分开实现的。
Dim st As String '目标内容
Dim FileName As String '文件名
'读取
Private Sub Command1_Click()
FileName = InputBox("请输入文件全名", , "c:\1.TXT")
st = Deal(FileName)
Print st
End Sub
'保存
Private Sub Command2_Click()
Dim fn As String
fn = InputBox("请输入文件全名", , FileName)
Open fn For Output As #112 '输出
Print #112, st
Close #112
End Sub
'处理函数
Private Function Deal(FileName As String) As String
If FileName = "" Then Exit Function
Dim s As String
Open FileName For Input As #112
While Not EOF(112)
Line Input #112, s
If s <> "" Then Deal = Deal & Right(s, 5) & vbNewLine
Wend
Close #112
End Function
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Dim a() As String
Private Sub Command1_Click()
Dim s As String, n As Long
n = -1
Open "c:\1.txt" For Input As #1
Do While Not EOF(1)
Line Input #1, s
If Len(s) = 18 Then
n = n + 1
ReDim Preserve a(n)
a(n) = Right(s, 5)
End If
Loop
Close #1
MsgBox "文件已打开"
End Sub
Private Sub Command2_Click()
Open "c:\2.txt" For Output As #1
For i = 0 To UBound(a)
Print #1, a(i)
Next i
Close #1
MsgBox "文件已保存"
End Sub
Private Sub Command1_Click()
Dim s As String, n As Long
n = -1
Open "c:\1.txt" For Input As #1
Do While Not EOF(1)
Line Input #1, s
If Len(s) = 18 Then
n = n + 1
ReDim Preserve a(n)
a(n) = Right(s, 5)
End If
Loop
Close #1
MsgBox "文件已打开"
End Sub
Private Sub Command2_Click()
Open "c:\2.txt" For Output As #1
For i = 0 To UBound(a)
Print #1, a(i)
Next i
Close #1
MsgBox "文件已保存"
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2013-03-15
展开全部
上边程序没有问题。
您试试换一台电脑。
或者看一下您的txt文件是不是在c盘目录下并且文件名是1.txt,
并且没有锁定或只读或目录不能访问等等。
您试试换一台电脑。
或者看一下您的txt文件是不是在c盘目录下并且文件名是1.txt,
并且没有锁定或只读或目录不能访问等等。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Dim b As String
Open "c:\1.txt" For Input As #1 '原始文件,文件名可自行更改
Open "c:\2.txt" For Append As #2 ‘结果保存文件,可自行更改
Do Until EOF(1)
Line Input #1, b
b = Right(b, 5)
Print #2, b
Loop
Close #2
Close #1
Open "c:\1.txt" For Input As #1 '原始文件,文件名可自行更改
Open "c:\2.txt" For Append As #2 ‘结果保存文件,可自行更改
Do Until EOF(1)
Line Input #1, b
b = Right(b, 5)
Print #2, b
Loop
Close #2
Close #1
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询