VB高手,请问以下代码为什么不能将以下txt文件中的12345678改成87654321,应该怎么改,谢谢您.
txt中有以下3行内容11111 12345678
t t t t 23.5 725 35.2 725 39.8 725
50.7 724 53.1 724 56.8 724
Private Sub Command1_Click()
On Error Resume Next
Dim a As String
Dim s As String
Dim ss() As String
Open "D:\ry.txt" For Input As #1
Open "D:\OB.txt" For Output As #2
Do Until EOF(1)
Line Input #1, s
ss = Split(Trim(s), " ")
ss(2) = 87654321
s = Join(ss, " ")
Print #2, s
Loop
Close #1
Close #2
End Sub --------------------编程问答-------------------- Private Sub CommandButton1_Click()
On Error Resume Next
Dim a As String
Dim s As String
Dim ss() As String
Dim dd()
Open "D:\ry.txt" For Input As #1
Open "D:\OB.txt" For Output As #2
Line Input #1, s
ss = Split(Trim(s), " ")
ss(1) = StrReverse(ss(1))
s = Join(ss, " ")
Print #2, s
Do Until EOF(1)
Line Input #1, s
Print #2, s
Loop
Close #1
Close #2
End Sub --------------------编程问答--------------------
Private Sub Command1_Click()--------------------编程问答-------------------- split分解串到数组,这个数组以0下标开始,所以
On Error Resume Next
Dim a As String
Dim s As String
Dim ss() As String
Open "D:\ry.txt" For Input As #1
Open "D:\OB.txt" For Output As #2
Do Until EOF(1)
Line Input #1, s
If i = 0 Then '只改第一行
ss = Split(Trim(s), " ")
ss(1) = 87654321 '索引为1,不是2
s = Join(ss, " ")
End If
S1 = S1 & s & vbCrLf
i = i + 1
Loop
Close #1
Print #2, S1
Close #2
End Sub
ss(2) = 87654321是错的,应该是ss(1)=87654321
--------------------编程问答-------------------- ss(1)="87654321" --------------------编程问答-------------------- 学习。。 --------------------编程问答--------------------
Private Sub Command1_Click()--------------------编程问答-------------------- Option Explicit '强制宣告定义变量
On Error Resume Next
Dim a As String
Dim s As String
Dim ss() As String
Open "D:\ry.txt" For Input As #1
Open "D:\OB.txt" For Output As #2
Do Until EOF(1)
Line Input #1, s
If i = 0 Then
ss = Split(Trim(s), " ")
ss(1) = 87654321
s = Join(ss, " ")
End If
S1 = S1 & s & vbCrLf
i = i + 1
Loop
Close #1
Print #2, S1
Close #2
End Sub
Dim aa$, jj& '定义变量
Private Sub Command1_Click()
'****************** 打开文件
Open "D:\ry.txt" For Input As #1
aa = StrConv(InputB(LOF(1), 1), vbUnicode)
Close #1
'****************** 将 12345678 反向, 如果你需要替换第二个以后的12345678则加上个循环即可
jj = InStr(aa, "12345678")
Mid(aa, jj, 8) = StrReverse(Mid(aa, jj, 8))
'****************** 重新写入文件
Open "D:\OB.txt" For Output As #1
Print #1, aa
Close #1
MsgBox "更新完成!"
End Sub
补充:VB , VBA