hi,

I want to ask about read data from .txt file and show them all to texbox in VB6
i just can do it for 1 line
anyone can help me?

sample like this :

Dim OutputPath As String
Dim sBaris$
Dim DROP() As Byte
Dim strTeks As String

OutputPath = "C:\Windows\Temp\RPLRECORD.TMP"

DROP = LoadResData(RPLRECORD.TXT, "CUSTOM")
Open OutputPath For Input As #1
Line Input #1, sBaris$
strTeks = strTeks & sBaris$
Close #1

Me.Text1.Text = strTeks

Thanks

Recommended Answers

All 4 Replies

Make sure the Text Box MultiLine property is set to True
You may have to add a vbcrlf to the text between reading lines.

Well, there is a bit more to it than that. Sorry I did not test before posting.
The following code works for me.

Private Sub Form_Click()
Dim FSO As New FileSystemObject
Dim OutputPath As String
Dim sBaris$
Dim DROP() As Byte
Dim strTeks As String

OutputPath = "C:\Program Files\Blank Calendar\MyBD.txt"

'DROP = LoadResData(RPLRECORD.TXT, "CUSTOM")
Open OutputPath For Input As #1


If Not EOF(1) Then
    Line Input #1, sBaris$
Else
    MsgBox "File Empty"
    Exit Sub
End Sub

Text1.Text = sBaris$

Do While Not EOF(1)
    Line Input #1, sbarist$
    Text1.Text = Text1.Text & vbCrLf & sbarist$
Loop
Close #1

'Me.Text1.Text = strTeks
End Sub

thank you for reply sir, but file which i want to access is on temporary file (.tmp). from my script on the top, i just can access it in the line 1 not more.

Well, that isn't what you ask. You asked about .txt files and your example uses .txt file. The "Line Input #" method is for use with sequential (text) files.

There are two issues here.
First, Did the code I posted work for the code you posted? If that code works would you please mark this thread as solved. I don't see how the code you posted would produce anything more than one line in the text box. You will have to loop the .txt file to capture all lines, and your code does not do that.

Secondly, If you have a question about reading .tmp files I suggest you post a new question that states that question and indicates code that attempts that.

For what it is worth:
From what I can find on temp files: They can be anything that an Internet program might want to save to your computer. They might be text, but might not, and what you get may only be gibberish especially if trying to open an exe.
It appears that most files can be opened in NotePad (select "All" under file type). Opening the file in NotePad may provide you with what your code was trying to do.
I delete all tmp files, so I have none to play with.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.