Tuesday, May 22nd 2012, 1:02am UTC+2

You are not logged in.

  • Login
  • Register

1

Monday, June 20th 2011, 1:47pm

Reading Text Files

Does anybody know how to read a text file (.txt) and display it in a scrollable textbox?

I have various text files (250-500 lines long) that I want to open and display in textbox.

Many thanks in advance!!!

Dani

Trainee

Posts: 68

Location: GERMANY

2

Tuesday, June 21st 2011, 6:20pm

Hey there,
I did not test it but something like this might work:

Jabaco Source

1
2
3
4
5
6
7
8
' read a file
Dim inputStream As New java#io#BufferedReader(New java#io#FileReader("c:\file.txt"))
Dim tmp() As String, i As Integer 
tmp() = Split(cStr(inputStream),";")
For i=0 To UBound(tmp())
List1.AddItem tmp(i)
Next i
Call inputStream.close()


I remember reading something like this posted in this forum.
Also there is quite a bit source code, e.g.:
Reading and writing binary data


Have fun,

Dani

Dani

Trainee

Posts: 68

Location: GERMANY

3

Tuesday, June 21st 2011, 7:01pm

oh I forgot...
Of course you will have to specify some kind of delimiter for your files
(";" in the above example) - vbcrlf for line end.

4

Saturday, June 25th 2011, 3:49am

Create a TextBox with MultiLine = True and scrollbars enabled. Then it can be as easy as:

Jabaco Source

1
2
3
4
5
6
7
8
9
10
11
12
13
14
Option Explicit
Public Sub Form_Load()
   Dim F As VBFileHandler
   Dim T As String
   
   Set F = FileSystem.Open("test.txt")
   Text1.Text = F.readAll()
   F.close
End Sub
Public Sub Form_Resize()
   If WindowState <> vbMinimized Then
      Text1.Move 0, 0, ScaleWidth, ScaleHeight
   End If
End Sub

Rate this thread
WoltLab Burning Board