我用程序打开一个文本文件,然后在文件里搜索到指定的字符(本例中是查找 A),将字符替换(本例中用H替换),代码如下:问题出在Replace 语句 ,不能实现,请问应该怎么实现啊!
注:text1.text 中显示 文件名的地址 text2.text显示要查找的字符
text3.text显示文件的内容
Private Sub Command1_Click() '实现查找替换
If text1.Text <> "" Then
Call ScanText(text1.Text, Text2.Text)
Replace(text3.Text ,"A","H")
End If
End SubPublic Sub ScanText(text1, findtxt)
Dim String1 As Single
Dim t1 As Variant
Dim t2 As Variant
Dim t3 As Variant
Dim t4 As Variant
Dim t5 As Variant
Dim t6 As Single
Open text1 For Binary As #1
t1 = LOF(1)
t2 = t1
t3 = 1
While t2 >= 0
If t2 > 32000 Then
t4 = 32000
ElseIf t2 = 0 Then
t4 = 1
Else
t4 = t2
End If
t7$ = String$(t4, " ")
Get #1, t3, t7$
String1! = InStr(1, LCase$(t7$), findtxt, 1)
If String1! Then
MsgBox "String was found in " + text1, 88
Close #1
Exit Sub
End If
MsgBox "String was not found in " + text1, 88
Close #1
Exit Sub
Wend
End Sub
注:text1.text 中显示 文件名的地址 text2.text显示要查找的字符
text3.text显示文件的内容
Private Sub Command1_Click() '实现查找替换
If text1.Text <> "" Then
Call ScanText(text1.Text, Text2.Text)
Replace(text3.Text ,"A","H")
End If
End SubPublic Sub ScanText(text1, findtxt)
Dim String1 As Single
Dim t1 As Variant
Dim t2 As Variant
Dim t3 As Variant
Dim t4 As Variant
Dim t5 As Variant
Dim t6 As Single
Open text1 For Binary As #1
t1 = LOF(1)
t2 = t1
t3 = 1
While t2 >= 0
If t2 > 32000 Then
t4 = 32000
ElseIf t2 = 0 Then
t4 = 1
Else
t4 = t2
End If
t7$ = String$(t4, " ")
Get #1, t3, t7$
String1! = InStr(1, LCase$(t7$), findtxt, 1)
If String1! Then
MsgBox "String was found in " + text1, 88
Close #1
Exit Sub
End If
MsgBox "String was not found in " + text1, 88
Close #1
Exit Sub
Wend
End Sub
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货