
Signature
.NET: It's About Trust!
http://vfred.mvps.org
Hi
I've used that function:
Public Function ReadFile(ByVal FileName As String) As String
Dim hFile As Long
On Error GoTo CodeErr
hFile = FreeFile
Open FileName For Binary As #hFile
ReadFile = Space$(LOF(hFile))
Get #hFile, , ReadFile
Close #hFile
CodeErr:
End Function
and I've created the array of "lines":
Dim TheLines() As String
TheLines = Split(ReadFile(strIniFile), vbCrLf)
But I have a problem with the InStr function.
If InStr(1, TheLines(i), sSignal, vbTextCompare) = 1 Then
ThisLine = Split(Trim$(TheLines(i)), " ")
sSignalFound = ThisLine(z)
sFinalCode = ThisLine(z + 1)
Else
MsgBox ("Signal not found in the txt document")
End If
The problem is with the following code:
If InStr(1, TheLines(i), sSignal, vbTextCompare) = 1
Then 'doesn't enter here
ThisLine = Split(Trim$(TheLines(i)), "
")
sSignalFound = ThisLine(z)
sFinalCode = "(" & ThisLine(z + 1) & " " &
ThisLine(z + 2) & " " & ThisLine(z + 3) & ")"
Else
MsgBox ("Signal not found in the txt document")
End If
It doesn't like "i", and if I put a number instead, for example 1, it
will work, but only for that array.
What condition should I put for i?
Helmut Weber - 29 Mar 2008 13:35 GMT
Hi,
not
>If InStr(1, TheLines(i), sSignal, vbTextCompare) = 1 Then
but
>If InStr(1, TheLines(i), sSignal, vbTextCompare) > 0 Then
Don't know what the rest of the code is supposed to do.
--
Greetings from Bavaria, Germany
Helmut Weber, MVP WordVBA
Vista Small Business, Office XP
Karl E. Peterson - 31 Mar 2008 20:34 GMT
> Hi
>
[quoted text clipped - 41 lines]
> will work, but only for that array.
> What condition should I put for i?
You'd want to use a For-Next loop for i...
For i = LBound(TheLines) To UBound(TheLines)
If InStr(1, TheLines(i), sSignal, vbTextCompare) = 1
' etc...
End If
Next i

Signature
.NET: It's About Trust!
http://vfred.mvps.org