11 Replies - 4461 Views - Last Post: 24 November 2013 - 10:05 AM

#1 Xenon   User is offline

  • Connection failed
  • member icon

Reputation: 9
  • View blog
  • Posts: 1,595
  • Joined: 12-September 05

Reading a Text file Line by Line

Posted 04 January 2006 - 06:04 AM

Description: add a textbox to the form and a command button, the names are default VB6 chosen namesReads and puts value in a textbox in its original text format.
'(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 SettingsSudeepMy Documents3.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



Is This A Good Question/Topic? 1
  • +

Replies To: Reading a Text file Line by Line

#2 karlamohan   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 26-July 08

Re: Reading a Text file Line by Line

Posted 21 August 2008 - 10:17 PM

The code is very usefull programmers like me Thank you
Was This Post Helpful? 0
  • +
  • -

#3 Rozie0910   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 13-October 08

Re: Reading a Text file Line by Line

Posted 15 October 2008 - 03:47 PM

can i apply this coding in vbnet?
Was This Post Helpful? 0
  • +
  • -

#4 hasoon   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 12-January 09

Re: Reading a Text file Line by Line

Posted 04 February 2009 - 07:54 PM

thank u very much for posting this.makes my life way easier. ^.^
Was This Post Helpful? 0
  • +
  • -

#5 nimrod   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 0
  • Joined: 23-April 09

Re: Reading a Text file Line by Line

Posted 23 April 2009 - 12:27 AM

great
Was This Post Helpful? 0
  • +
  • -

#6 darfun   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 0
  • Joined: 01-May 09

Re: Reading a Text file Line by Line

Posted 30 April 2009 - 11:23 PM

Nice code Xenon, this simple and easy to understand and use code really force me to encourage you for the good work. im a bigner and this code is really good for newbies. now i,ll be searching for the code to write to text files. thanks man
Was This Post Helpful? 0
  • +
  • -

#7 masserra   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 0
  • Joined: 07-May 10

Re: Reading a Text file Line by Line

Posted 07 May 2010 - 05:44 PM

Thank you very much... great code.... god bless you!
Was This Post Helpful? 0
  • +
  • -

#8 wildbits   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 0
  • Joined: 18-July 10

Re: Reading a Text file Line by Line

Posted 18 July 2010 - 06:54 AM

Very nice. Thanks a lot!!
Was This Post Helpful? 0
  • +
  • -

#9 bozo   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 0
  • Joined: 20-August 10

Re: Reading a Text file Line by Line

Posted 20 August 2010 - 06:25 AM

I learnig "Visual basic" and I donīt understand why textbox show only one line of text.
Was This Post Helpful? 0
  • +
  • -

#10 Firya   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 24-November 10

Re: Reading a Text file Line by Line

Posted 12 July 2011 - 11:31 PM

gread code thank yoiu
Was This Post Helpful? 0
  • +
  • -

#11 svcongnghe   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 0
  • Joined: 13-July 12

Re: Reading a Text file Line by Line

Posted 14 July 2012 - 08:53 PM

so i have a problem for this codes thank for your codes! it's great, but i have a problem it's "run-time error 424. object require" despite of I typed exactly. and i don't know number codes 24. what's "Text1", and what does this mean???
Was This Post Helpful? 0
  • +
  • -

#12 aaronpl   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 0
  • Joined: 24-November 13

Re: Reading a Text file Line by Line

Posted 24 November 2013 - 10:05 AM

try my html generator at htmleasy.weebly.com it is fast and easy :) If you like it, please donate/click the google +1 button
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1