如何使用 vb 6 打印 .txt 文件中文本的每一行
How to print every second line of the text in .txt file using vb 6
我有一个程序可以从 .txt 文件中读取所有信息,然后显示在 MsgBox 中。需要知道,如何从此文件中每隔一行(每隔一个名字)打印一次并显示在 MsgBox 中。这是我的代码:
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
这是 .txt 文件的样子
Here is how it showing now in MsgBox
:
试试这个:
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
我有一个程序可以从 .txt 文件中读取所有信息,然后显示在 MsgBox 中。需要知道,如何从此文件中每隔一行(每隔一个名字)打印一次并显示在 MsgBox 中。这是我的代码:
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
这是 .txt 文件的样子
Here is how it showing now in MsgBox
:
试试这个:
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