Hey all,
I am trying to figure out the open command.
could someone give me the simplest example of how to use this?
I would like to open a .txt file and display it on my form.
thanks
Printable View
Hey all,
I am trying to figure out the open command.
could someone give me the simplest example of how to use this?
I would like to open a .txt file and display it on my form.
thanks
I'm not sure about the correct syntax, but I'm quite sure it will work (NOTE: you should use FreeFile property instead of #1 thing)Code:Open "C:\MyTextFile.txt" For Input As #1
Text1.Text = Input(LOF(1),#1)
Close #1
HTH
(change: Use LOF instead of EOF)
[Edited by QWERTY on 07-15-2000 at 12:02 PM]
Code:Dim strTemp As String
Open "C:\txt.txt" For Input As #1
Do Until EOF(1) = True
Line Input #1, strTemp
If Text1.Text = "" Then
Text1.Text = strTemp
Else
Text1.Text = Text1.Text & vbCrLf & strTemp
End If
Loop
Close #1
I think this is what you mean
open "c:\text.txt" for input as #1 'Open the file
do
line input #1, textline 'Get one line of text
print textline 'Print the line of txt
'on your form
loop until eof(1) 'Do until end of file
close #1
That should work. I just made it here so there might be some small bugs but I think you understand the code.
Worf
hint:
in a do-loop block, always put the decision clause after the Do word, unless you want to force it to run through the code at least once.
K. Thanks wossname I'll remember that.
I'm using a Rich TextBox and the command
Text1.Loadfile "C:\textfile.txt"
And for saving
Text1.Savefile "C:\textfile.txt"
Th string "C:\textfile.txt" can of course be substituted with a string variable.
Pentax
Qwerty, regarding your post. It is not necessary to change LOF to EOF. LOF is the one you should use in this case.