i have create a basic vb application...i using vb6. i got external file in the same folder name a.txt
so how do i can display the text file on the vb application?
Printable View
i have create a basic vb application...i using vb6. i got external file in the same folder name a.txt
so how do i can display the text file on the vb application?
Welcome to the Forums.
Here is a link to a Tutorial on File I/O
Instead of showing the file contents to a message box, you can
display it in a textbox by setting the textbox's .Text property to
the value of the variable.
HTH
Definetly read RobDog's tutorial.
Here's an identical approach in binary mode. It's generally not used with ASCII files, but might prove to be slightly faster for larger files (but who's counting these days).
Someone should add binary files to that tutorial.VB Code:
Dim sTmp As String sTmp = Space$(FileLen("C:\myfile.txt")) Open "C:\myfile.txt" For Binary Access Read As #1 Get #1, , sTmp Close #1 Text1.Text = sTmp
do i need to add label or listbox to place it on my vb application and i just want to view the text file only...i got a basic application to generate number...so after user click to Generate Command button, a space of showing the text file will be apear...
Actually Mega, its B-Rabbit/Algar's Tutorial.
Wish I could take the credit though :(
No, just a textbox and a commandbutton.
And change the path of the file to reflect the file you want to open.
Where are you getting Label's and ListBoxes from?
If you have multiple lines of data to display, then using a textbox
with its .Multiline property set to True will do. Also, enable the
scrollbars too.
Is it like this?
Private Sub Text6_Change()
Dim sTmp As String
sTmp = Space$(FileLen("file.txt"))
Open "file.txt" For Binary Access Read As #1
Get #1, , sTmp
Close #1
End Sub
Put it in a command button's click() event, not the change() event of your textbox.
nothing appear on the textbox...my textbox name is Text6
Did you specify the correct path?
Did you add
Text6.Text = sTmp
at the end of your code?
oh great thanks...
brainwash
You can also use an RTF Textbox and not have to write much code to read and display the file. Two to thre lines I believe.