I have a text file (about 20 meg) where each record is 350
characters(+crlf). Back in the DOS days I Line Input opened the file and
printed the first 60 characters to the screen in a Do Until EOF(1), print
data$ fashion. It scrolled by slow enough for me to recognize any gross
errors in certain fields and/or "character creep" in the imported data. It
was a simple exercise and gave me confidence in the data and the fact it was
processing . I dont know why Im having trouble doing this in VB6, can
someone give me a quick example? I would like to be able to see the last 20
or so data records still on the screen when it comes to the end of the file.
Thanks.
Jim Mack - 28 Sep 2004 13:23 GMT
> I have a text file (about 20 meg) where each record is 350
> characters(+crlf). Back in the DOS days I Line Input opened the file
[quoted text clipped - 7 lines]
> records still on the screen when it comes to the end of the file.
> Thanks.
One way would be to use a ListBox to hold the data items. If you have
no interest in anything except the last N items, here's one way to do
that (air code).
Start with the listbox sized to show the number of lines you care to see
at once. N/2 lines might be a convenient number, or maybe all N --
whatever you like.
Option Explicit
Private Sub Command1_Click
Const nLines As Long = 20
Dim hFile As Long
Dim Buff As String
List1.Clear
hFile = FreeFile
Open Text1.Text For Input As hFile
Do Until EOF(hFile)
Line Input #hFile, Buff
With List1
If .ListCount > nLines Then
.RemoveItem 0
End If
.AddItem Left$(Buff, 60)
.TopIndex = .ListCount - 1 'latest at the bottom
.Refresh
End With
Sleep 100 ' gives time to read screen
Loop
Close #hFile
End SUb
Maybe choose the Sleep value with a slider -- if so, add a DoEvents so
the form will be responsive.

Signature
Jim Mack
MicroDexterity Inc
www.microdexterity.com
Frank Adam - 28 Sep 2004 14:01 GMT
>I have a text file (about 20 meg) where each record is 350
>characters(+crlf). Back in the DOS days I Line Input opened the file and
[quoted text clipped - 6 lines]
>or so data records still on the screen when it comes to the end of the file.
>Thanks.
Another way is to add a timer to your Form and let it read the chunks
of 20 records, adding it to (or replacing the contents of) a multiline
Textbox.
In fact, there is even an easier solution. The RichTextBox should be
able to handle a 20 meg file without problems. So just read the file
with the RichTextbox's loadfile function. Then have a timer fire off
an EM_LINESCROLL message to the box at a suitable period.
Add a RichTextBox to your Form and paste this code in.
You may want to add a pause/start button too, so you can pause and
restart at will, by dis- or en-abling the timer.
Option Explicit
Private Const EM_LINESCROLL = &HB6
Private Declare Function SendMessage Lib "user32" Alias _
"SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, _
ByVal wParam As Long, lParam As Any) As Long
Private Sub Form_Load()
Timer1.Enabled = False
Timer1.Interval = 2000
RichTextBox1.LoadFile "insert your file's path here"
Timer1.Enabled = True
End Sub
Private Sub Timer1_Timer()
'scroll 1 line at a time.
' Return value from SendMsg is the number of lines scrolled
If SendMessage(RichTextBox1.hwnd, EM_LINESCROLL, 0, _
ByVal 1) = 0 Then
'we're done, so disable the timer.
Timer1.Enabled = False
End If
End Sub

Signature
Regards, Frank