我有一個程式可以從 .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: 
uj5u.com熱心網友回復:
嘗試這個:
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
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/377726.html
