• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 167
  • Last Modified:

Reading Sequencial file line by line

VB command to read a sequencial file line by line in a buffer without losing any spaces.
the file contains 79 long records per line. I want to read
each line in a variable that ends up to contain 79 chars including spaces.
thanks
0
g6yassin
Asked:
g6yassin
1 Solution
 
wj7sterCommented:
Your question is a little vague....If I understand you correctly you can try this:

Dim sLine     As String

' * * * * * * *

Open pathtofile For Input As #1

While Not EOF(1)
 Line Input #1, sLine
Wend


0
 
a111a111a111Commented:
Hi,
If you want to have all the lines in an array or a textbox
here is a small code for it.

=========== START CODE =============

Private Sub Command1_Click()
Dim OneLine$
Dim AllLines$
Dim inFile
Dim Wrap

Wrap = Chr$(13) & Chr(10)

'* you can use this to open a file or
'*(you need a component: COMDLG32.OCX) >>>
'* CommonDialog1.ShowOpen
'* Open CommonDialog1.filename For Input As #1

'* >>> You can use this to open a file
'* path(myFolder) and file name (myFile.txt)
inFile = "c:\myFolder\myFile.txt"
Open inFile For Input As #1

While Not EOF(1)
    Input #1, OneLine
    AllLines = AllLines & OneLine & Wrap
Wend

Close #1
Text1.Text = AllLines '* (Make Text1.text MultiLine=true)
End Sub


======== END CODE ========


Notes:

1. The Textbox limited to 32 KB.

2. You can use array like A(i) to hold the lines one by one but    than you need to count the number of lines first.

3. You can write to a new file (post if you need the code).

- What do you want to do with the lines?

I hope it helps some.

Shay.


0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now