I have a program that reads all info from .txt file and after this showing in MsgBox. Need to know, how to print every second line (every second name) from this file and show in MsgBox. Here is my code:
Sub Printed
Dim sFileText As String
Dim sFinal as String
Dim iFileNo As Integer
iFileNo = FreeFile
Open "D:\Information\data.txt" For Input As #iFileNo
Do While Not EOF(iFileNo)
Input #iFileNo, sFileText
sFinal = sFinal & sFileText & vbCRLF
Loop
MsgBox sFinal
Close #iFileNo
End Sub
Here is, how .txt file looks
Here is how it showing now in MsgBox
:
CodePudding user response:
Try this:
Sub Printed
Dim sFileText As String
Dim sFinal as String
Dim iFileNo As Integer
Dim fIgnoreLine As Boolean
iFileNo = FreeFile
' fIgnoreLine = True ' uncomment this line if you want to print every even line
Open "D:\Information\data.txt" For Input As #iFileNo
Do While Not EOF(iFileNo)
Line Input #iFileNo, sFileText
if Not fIgnoreLine then sFinal = sFinal & sFileText & vbCRLF
fIgnoreLine = Not fIgnoreLine
Loop
MsgBox sFinal
Close #iFileNo
End Sub