[RESOLVED] search untile empty line
small Q1:
how can i stop searching a .txt file if i reach an empty line? :rolleyes:
small Q2: :o
if i got what i'm searching
VB Code:
If UCase(Left(tmp(x), 14)) = Text3.Text Then
how can i add a char ,for example ">" in position 15 in the file
:wave:
Re: search untile empty line
Q1: what is the code you are using to search the .txt file...
Re: search untile empty line
For question 1:
VB Code:
Private Sub Form_Load()
Dim data As String
Open "C:\test.txt" For Input As #1
Do While EOF(1) <> True
Line Input #1, data
If Len(Replace(data, " ", "")) = 0 Then Exit Do
Debug.Print data
Loop
Close #1
End Sub
Re: search untile empty line
@Rob123: you'd probably be better using Trim$ for that line:
VB Code:
If Len(Trim$(Data)) = 0 Then Exit Do
Re: search untile empty line
VB Code:
If UCase(Left(tmp(x), 14)) = Text3.Text Then tmp(x) = left(tmp(x), 14) & ">" & mid(tmp(x), 15)
the above should work if you want the whole string with > inserted at that position, if you just want the first part and the > then leave off the mid part
Re: search untile empty line
hi westconn1
OK this code is adding the char to tmp(x)
i checked that by this code
now how it can be copied to the text file?
Re: search untile empty line
assuming the array tmp is a split of the file you opened and that you just want to overwrite it, then open the same (or other) file for output, join the array and print to file
this is after all substitutions are done, so that you only write to file once
VB Code:
Open myfile For Output As 1
Print #1, Join(tmp, vbNewLine)
Close 1
Re: search untile empty line
thanks alot westconn1
i've done it