Code Snippets

  

Visual Basic Source Code


Welcome to Dream.In.Code
Getting VB Help is Easy!

Join 99,787 VB Programmers for FREE! Ask your question and get quick answers from experts. There are 1,577 online right now! We've got more than 500 tutorials and 2,000 snippets. Join and find out why Dream.In.Code is the #1 programming help community on the internet! Registration is fast and FREE... Join Now!




Reading a Text file Line by Line

Reads and puts value in a textbox in its original text format.

Submitted By: Xenon
Actions:
Rating:
Views: 38,667

Language: Visual Basic

Last Modified: January 4, 2006
Instructions: add a textbox to the form and a command button, the names are default VB6 chosen names

Snippet


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

Copy & Paste


Comments


There are currently no comments for this snippet. Be the first to comment!

Add comment


You must be registered and logged on to </dream.in.code> to leave comments.





Live VB Help!

VB Tutorials

Reference Sheets

VB Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month
-->