5 Replies - 48646 Views - Last Post: 11 June 2008 - 03:51 AM Rate Topic: -----

#1 jrivera  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 09-June 08

How to read a text file in VB6

Posted 09 June 2008 - 12:11 PM

I want to read the text file per lines. How can I do this using Visual Basic 6.0. I want to know also how to get the lenght of each lines in the text file.

thanks.
Is This A Good Question/Topic? 0
  • +

Replies To: How to read a text file in VB6

#2 Zhalix  Icon User is offline

  • D.I.C Regular

Reputation: 20
  • View blog
  • Posts: 260
  • Joined: 07-May 08

Re: How to read a text file in VB6

Posted 09 June 2008 - 06:16 PM

Read this, it'll give you a lot of information on reading text files (and you'll learn about 'Line Input' which takes entire lines and ignores commas):

http://www.dreaminco...wtopic29575.htm


Here's a tutorial on strings and their handy functions (including the Len() function which you'll wanna use to get the length of the lines):

http://www.dreaminco...wtopic13107.htm


If you still can't figure it out, post again but this time with your code and also explaining any errors you're encountering.

This post has been edited by Zhalix: 09 June 2008 - 06:24 PM

Was This Post Helpful? 0
  • +
  • -

#3 jrivera  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 09-June 08

Re: How to read a text file in VB6

Posted 10 June 2008 - 07:58 AM

Private Sub Form_Load()
Dim tmp As String
Open "C:\Ultra Occlusion.txt" For Input As #1
Line Input #1, tmp
Close #1
MsgBox tmp
End Sub

its working but I want to read the 2nd line (PS CS S2..) without the space too.. How can I do that.???

EXAMPLE DATA: Ultra Occulsion

SampleRate 1000
P2 CS S2 S3 S4 S5 ECG
START DATA
9.96820 35.5268 5.53845 14.3396 11.1619 4.44403 0.329678


thanks alot for your quick reply,
Joel

View PostZhalix, on 9 Jun, 2008 - 06:16 PM, said:

Read this, it'll give you a lot of information on reading text files (and you'll learn about 'Line Input' which takes entire lines and ignores commas):

http://www.dreaminco...wtopic29575.htm


Here's a tutorial on strings and their handy functions (including the Len() function which you'll wanna use to get the length of the lines):

http://www.dreaminco...wtopic13107.htm


If you still can't figure it out, post again but this time with your code and also explaining any errors you're encountering.

Was This Post Helpful? 0
  • +
  • -

#4 Zhalix  Icon User is offline

  • D.I.C Regular

Reputation: 20
  • View blog
  • Posts: 260
  • Joined: 07-May 08

Re: How to read a text file in VB6

Posted 10 June 2008 - 12:29 PM

Well I don't think there's a way to start reading a file on any specific line.

You have to start at the beginning and work your way in to find the second line (which is near the top so it's not a problem anyway).

I simply made a copy of the bit of code that extracts the line.
This is because every time you call "Line Input" it will start on the next line.

Private Sub Form_Load()

Dim strTemp As String

Open "C:\Ultra Occlusion.txt" For Input As #1

	Line Input #1, strTemp
	Line Input #1, strTemp

Close #1

MsgBox strTemp

End Sub



Pretty simple huh? It finds the first line and puts it into "strTemp", and then it finds the second line and replaces the original data in "strTemp" with the data from the second line.

You said you wanted it without the spaces too. Well, to do that you'll wanna use the Replace function.

Replace(Original String, Look For This, Replace With This)
strTemp = Replace(strTemp, " ", "")


Finds any spaces and replaces them with nothing.


In the future remember to use the [code ] [/code ] tags to contain your code. It makes it easier to look through (and also just looks pretty).

This post has been edited by Zhalix: 10 June 2008 - 12:44 PM

Was This Post Helpful? 0
  • +
  • -

#5 Locke  Icon User is offline

  • Sarcasm Extraordinaire!
  • member icon

Reputation: 520
  • View blog
  • Posts: 5,596
  • Joined: 20-March 08

Re: How to read a text file in VB6

Posted 10 June 2008 - 05:15 PM

Well, the way I learned was not to use Line Input, but just regular Input.

Private Sub Form_Load()

    Dim str(5) As String

    Open "C:\Ultra Occlusion.txt" For Input As #1

        Input str(0), str(1), str(2), str(3), str(4)

    Close #1

    'Process the data in the array.

End Sub


I think there's a way to set a delimiter, maybe that's just in VB.NET. I haven't used VB6 since school got out.

This post has been edited by Locke37: 10 June 2008 - 05:16 PM

Was This Post Helpful? 0
  • +
  • -

#6 born2c0de  Icon User is offline

  • printf("I'm a %XR",195936478);
  • member icon

Reputation: 180
  • View blog
  • Posts: 4,667
  • Joined: 26-November 04

Re: How to read a text file in VB6

Posted 11 June 2008 - 03:51 AM

Quote

I think there's a way to set a delimiter, maybe that's just in VB.NET. I haven't used VB6 since school got out.

Not in VB6. You're forced to use the comma as a delimiter.
You can however use Line Input and remove your custom delimiters.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1