只要找到了指定的字符串,可以在它后面直接插入新行。代码如下: 运行时只需在窗体上点击以下便可。 private sub form_click() q=inputbox("请输入要查找的字符串") open "路径" for input as #1 x=input(lof(1),1) close y=instr(1,x,q) if y<>0 then print"找到字符串";q else print"未找到字符串";q end if end sub 注意:open后的“路径”为你要打开的文件,例如:c:\aaa.txt
用API函数 Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long
Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As String) As Long
文件c:\txt1.txt [value] vale1 vale1 ... dim n as long n=GetPrivateProfileString(...) if n>0 then WritePrivateProfileString(...) end if lpApplicationName :[value] lpKeyName:value lpString:vbNullString nSize:字符串长度 lpFileName:c:\txt1.txt
阿龙这句出错误了! x=input(lof(1),1)
Private Sub Form_Load() Dim Strtmp As String Open "c:\转码.txt" For Input As #1 Open "c:\转码1.txt" For Output As #2k = 1 Do While Not EOF(1) Line Input #1, Strtmp If InStr(Strtmp, "AAC") <> 0 Then ’AAC即是你要查找的字符串 Print #2, Strtmp Print #2, "" Else Print #2, Strtmp End If k = k + 1 Loop End Sub
[key1]
data1=...
data2=...
data2=...
...
运行时只需在窗体上点击以下便可。
private sub form_click()
q=inputbox("请输入要查找的字符串")
open "路径" for input as #1
x=input(lof(1),1)
close
y=instr(1,x,q)
if y<>0 then
print"找到字符串";q
else
print"未找到字符串";q
end if
end sub
注意:open后的“路径”为你要打开的文件,例如:c:\aaa.txt
Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long
Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As String) As Long
[value]
vale1
vale1
...
dim n as long
n=GetPrivateProfileString(...)
if n>0 then
WritePrivateProfileString(...)
end if
lpApplicationName :[value]
lpKeyName:value
lpString:vbNullString
nSize:字符串长度
lpFileName:c:\txt1.txt
x=input(lof(1),1)
Dim Strtmp As String
Open "c:\转码.txt" For Input As #1
Open "c:\转码1.txt" For Output As #2k = 1
Do While Not EOF(1)
Line Input #1, Strtmp
If InStr(Strtmp, "AAC") <> 0 Then ’AAC即是你要查找的字符串
Print #2, Strtmp
Print #2, ""
Else
Print #2, Strtmp
End If
k = k + 1
Loop
End Sub