You are not logged in.

Dear visitor, welcome to Jabaco - Community. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

IsoCAM

Beginner

  • "IsoCAM" started this thread

Posts: 2

Date of registration: Jun 19th 2011

  • Send private message

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

Intermediate

Posts: 325

Date of registration: Nov 19th 2009

Location: GERMANY

  • Send private message

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

Intermediate

Posts: 325

Date of registration: Nov 19th 2009

Location: GERMANY

  • Send private message

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.

dilettante

Beginner

Posts: 8

Date of registration: Jan 28th 2011

  • Send private message

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