-
I've tried a few different approaches to this problem, and I'm sure that you guys are gonna present me w/ an east solution but here goes. I'm trying to read an entire text file into a text box but no matter how I do it I can only get it to read the very last line into the text box. (yes, multi-line is true) I can't figure out what's the problem with my code. I would post it but I don't have it on this system. Anyway. Thanks in advance.
-
are you ADDING each line to the text box or replacing the text each time by mistake?
Code:
do
...
...
Textbox.text = LineFromFile
...
...
loop
when you should do this:
Code:
do
...
...
Textbox.text = Textbox.text & LineFromFile
...
...
loop
Just a thought.
-
You can try this...
Example :
Open "C:\Windows\config.txt" For Input As #1
Do While Not EOF(1)
Input #1, myStr
Text1.Text = Text1.Text & myStr & Chr$(13) & Chr$(10)
Loop
Close #1
Note : The Chr$(13) is a Carriage Return ASCII Code to return to the begining of line and Chr$(10) is a Line Feed ASCII Code to Jump to a new line. (You can take them off if this is not what you want)
Hope this sample coding helps you with your problem.
Good Luck!
-
You remembered Multi-line, but what about ScrollBars?
Either way, here is your code modified to work:
Code:
Dim mystr As String
Dim iFileNum As Integer
iFileNum = FreeFile
Open "C:\Windows\config.txt" For Input Access Read Shared As #iFileNum Len = MAXSHORT
Screen.MousePointer = vbHourglass
Text1.Enabled = False
Do While Not EOF(iFileNum)
Input #iFileNum, mystr
Text1.Text = Text1.Text & mystr & vbCrLf
DoEvents
Loop
Text1.Enabled = True
Screen.MousePointer = vbDefault
Close #iFileNum
However, the way you are doing it is not very efficient, try using the following method instead.
Use each method on the same file to see what I mean.
Code:
Dim iFileNum As Integer
iFileNum = FreeFile
Open "C:\Windows\config.txt" For Input Access Read Shared As #iFileNum Len = MAXSHORT
Text1.Text = Input(LOF(iFileNum), #iFileNum)
Close #iFileNum
Later.
[Edited by SonGouki on 04-17-2000 at 06:00 PM]
-
Maybe you should try a RichTextBox instead.
In that case, the code would be as simle as
Text1.Loadfile C:\textfile.txt [or any other file]
Good luck!
Pentax
-
Thanks for all the help guys. THe problem was that I was overwriting instead of appending. Oh, and yes I did have the scroll bars set to true :)