|
-
April 5th, 2000, 05:32 PM
#1
text file opening
hello, i made a text file program like notepad where you save and open text files, but when i open a text file with spaces it only opens one line of it, heres the code for opening it, tell me whats wrong:
Private Sub mnuopen_Click()
On Error GoTo h
Dim strTemp As String
dlg.Filter = "Text files (*.txt)|*.txt"
dlg.FileName = "*.txt"
dlg.ShowOpen
If Dir(dlg.FileName) > "" Then
Open dlg.FileName For Input As #1
Line Input #1, a
text1 = a
Close #1
Else
MsgBox "File not found", vbExclamation, "Error" & Err.Description
End If
h:
End Sub
-
April 5th, 2000, 10:31 PM
#2
Re: text file opening
Well, It looks as if you only read one line. You would have to add the following code to read the rest.
Open dlg.FileName for input as #1
while not eof(1)
Line input #1, a
text1 = text1 & a
wend
Close #1
David Paulson
-
April 6th, 2000, 01:26 PM
#3
Re: text file opening
You may also have to add a cr/lf
text1 = text1 & vbcrlf
David Paulson
-
April 6th, 2000, 01:50 PM
#4
Re: text file opening
Your code only reads one line of the source file - you could do what the above post suggests. I personally have become very partial to the object way of using text files - the FileSystemObject:
'set a reference to the Microsoft Scripting Runtime
private Sub mnuopen_Click()
Dim FSO as Scripting.FileSystemObject
Dim Filer as Scripting.TextStream
Dim sFile as string
Dim strTemp as string
on error GoTo h
dlg.Filter = "Text files (*.txt)|*.txt"
dlg.FileName = "*.txt"
dlg.ShowOpen
If Dir(dlg.FileName) > "" then
sFile = dlg.FileName
set FSO = new Scripting.FileSystemObject
set Filer = FSO.OpenTextFile(sFile, ForWriting, false)
text1.Text = filer.readall
Filer.Close
else
MsgBox "File not found."
End If
set Filer = nothing
set FSO = nothing
End Sub
Hope that helps,
John
John Pirkey
MCSD
http://www.ShallowWaterSystems.com
http://www.stlvbug.org
John Pirkey
MCSD (VB6)
http://www.stlvbug.org
-
April 16th, 2000, 09:16 PM
#5
Re: text file opening
Add a loop to scan from the begin to the end of file :
open ....
while not eof (1)
line input #1, a$
text1 = text1.text & a$
loop
close 1
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|