VB完成按行讀取文本文件的辦法。本站提示廣大學習愛好者:(VB完成按行讀取文本文件的辦法)文章只能為提供參考,不一定能成為您想要的結果。以下是VB完成按行讀取文本文件的辦法正文
本文實例講述了VB完成按行讀取文本文件的辦法。分享給大家供大家參考。詳細如下:
'(general declaration) Dim nFileNum As Integer, sText As String, sNextLine As String, lLineCount As Long '================================== Private Sub Command1_Click() ' Get a free file number nFileNum = FreeFile ' Open a text file for input. inputbox returns the path to read the file Open "C:\Documents and Settings\Sudeep\My Documents\3.txt" For Input As nFileNum lLineCount = 1 ' Read the contents of the file Do While Not EOF(nFileNum) Line Input #nFileNum, sNextLine 'do something with it 'add line numbers to it, in this case! sNextLine = sNextLine & vbCrLf sText = sText & sNextLine Loop Text1.Text = sText ' Close the file Close nFileNum End Sub
希望本文所述對大家的VB順序設計有所協助。