请选择 进入手机版 | 继续访问电脑版
查看: 210|回复: 0

[.NET开发] 按行读取文本文件

3万

主题

3万

帖子

10万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
100197
发表于 2015-11-23 17:52:09
<无详细内容>
  1. '(general declaration)
  2. Dim nFileNum As Integer, sText As String, sNextLine As String, lLineCount As Long
  3. '==================================
  4. Private Sub Command1_Click()
  5. ' Get a free file number
  6. nFileNum = FreeFile
  7. ' Open a text file for input. inputbox returns the path to read the file
  8. Open "C:\Documents and Settings\Sudeep\My Documents\3.txt" For Input As nFileNum
  9. lLineCount = 1
  10. ' Read the contents of the file
  11. Do While Not EOF(nFileNum)
  12. Line Input #nFileNum, sNextLine
  13. 'do something with it
  14. 'add line numbers to it, in this case!
  15. sNextLine = sNextLine & vbCrLf
  16. sText = sText & sNextLine
  17. Loop
  18. Text1.Text = sText
  19. ' Close the file
  20. Close nFileNum
  21. End Sub
复制代码


回复

使用道具 举报