ljavier34
Mechanical
- Dec 2, 2005
- 13
I've been trying to do this for the past few days and cannot get it. All I want to do is break and initial text file that has a whole bunch of information in two files that contain only the lines that start with ND in one file, and the other file with all the lines that start with EL.
a Sample text file would be something like this...
flajfl
afalfj
ND, 3 4 5
ND, 3 6 7
EL, 1 2 3
EL 123
I was trying to use the split function, but I got all confused with it...This is what I have so far...I am looking for the letter "H" as the start of the line in this code...
Sub Perm()
Dim variable1 As String
Dim StartTag As String
Dim TextIn As String
Dim EndTag As String
Dim lArray As Variant
StartTag = "H"
Wrap$ = Chr$(13) + Chr$(10)
EndTag = Wrap$
Open "C:\Documents and Settings\Javier B\Desktop\sample.txt" For Input As #1
Do Until EOF(1)
Input #1, variable1
Alltext$ = Alltext$ & variable1 & Wrap$
Loop
charsInFile = Len(Alltext$)
For i = 1 To charsInFile
letters = Mid(Alltext, i, 1)
If letters = Chr(13) Then
j = i + 1
sentence = Mid(Alltext, j)
'Debug.Print sentence
TextIn = sentence
Extract = " "
lArray = Split(TextIn, StartTag)
'If IsArray(lArray) Then
Extract = lArray(0)
Debug.Print lArray(0)
'lArray = Split(Extract, EndTag)
'If IsArray(lArray) Then
'Extract = lArray(0)
'Else
'Extract = " "
'End If
'End If
'Debug.Print Extract
End If
Next i
Close #1
End Sub
Any help or guidance would be greatly appreciated...
Thank you,
Javier
a Sample text file would be something like this...
flajfl
afalfj
ND, 3 4 5
ND, 3 6 7
EL, 1 2 3
EL 123
I was trying to use the split function, but I got all confused with it...This is what I have so far...I am looking for the letter "H" as the start of the line in this code...
Sub Perm()
Dim variable1 As String
Dim StartTag As String
Dim TextIn As String
Dim EndTag As String
Dim lArray As Variant
StartTag = "H"
Wrap$ = Chr$(13) + Chr$(10)
EndTag = Wrap$
Open "C:\Documents and Settings\Javier B\Desktop\sample.txt" For Input As #1
Do Until EOF(1)
Input #1, variable1
Alltext$ = Alltext$ & variable1 & Wrap$
Loop
charsInFile = Len(Alltext$)
For i = 1 To charsInFile
letters = Mid(Alltext, i, 1)
If letters = Chr(13) Then
j = i + 1
sentence = Mid(Alltext, j)
'Debug.Print sentence
TextIn = sentence
Extract = " "
lArray = Split(TextIn, StartTag)
'If IsArray(lArray) Then
Extract = lArray(0)
Debug.Print lArray(0)
'lArray = Split(Extract, EndTag)
'If IsArray(lArray) Then
'Extract = lArray(0)
'Else
'Extract = " "
'End If
'End If
'Debug.Print Extract
End If
Next i
Close #1
End Sub
Any help or guidance would be greatly appreciated...
Thank you,
Javier