|
-
Oct 10th, 2001, 05:01 PM
#1
Thread Starter
Hyperactive Member
How do i make a txt files?
How could my program make like "C:File.txt"?
-
Oct 10th, 2001, 05:02 PM
#2
-= B u g S l a y e r =-
VB Code:
Private Sub Command1_Click()
Open "C:\rattata.txt" For Output As #1
Print #1, "test" 'exclude quotes
Write #1, "test" 'include quotes
Close #1
End Sub
-
Oct 10th, 2001, 05:02 PM
#3
PowerPoster
VB Code:
Open "C:\File.txt" For Output as #1
Print#1, ""
Close #1
should do it
-
Oct 10th, 2001, 05:02 PM
#4
Member
To write to a text file (this creates it if it does not exist already):
VB Code:
Dim FileHandle As Integer
Open "c:\file.txt" For Output As #FileHandle
Print #FileHandle, "Testing"
Close #FileHandle
-
Oct 10th, 2001, 05:03 PM
#5
Member
Oh, and if you want to read it back in :
VB Code:
Dim FileHandle As Integer
Dim Contents As String, Cache As String
Open "c:\file.txt" For Input As #FileHandle
Line Input #1, Cache
Contents = Contents & Cache & vbCrLf
Close #FileHandle
Contents = Right$(Contents, Len(Contents) - 1) ' get rid of trailing newline
-
Oct 10th, 2001, 05:03 PM
#6
PowerPoster
I'm sure theres a conspiracy going on here
-
Oct 10th, 2001, 05:04 PM
#7
Member
I gave the most code, I want a cookie.
-
Oct 10th, 2001, 05:04 PM
#8
-
Oct 10th, 2001, 05:45 PM
#9
Hey you guys forgot about the filesystemobject! 
VB Code:
Option Explicit
Dim fso As New FileSystemObject
Private Sub Form_Load()
Dim tsr As TextStream
Dim myFSOText As String
myFSOText = "d:\anypath\text.txt"
If fso.FileExists(myFSOText) = False Then
Set tsr = fso.CreateTextFile(myFSOText)
Else
Set tsr = fso.OpenTextFile(myFSOText, ForAppending)
End If
tsr.Write "blah"
tsr.Close
Set tsr = Nothing
End Sub

regards,
Helger
-
Oct 10th, 2001, 05:48 PM
#10
Frenzied Member
Nooooooooooooo The FSO people found the thread!!! Were all dooooooomed!!
You just proved that sig advertisements work.
-
Oct 10th, 2001, 05:49 PM
#11
PowerPoster
All that code, and 3 lines of intrinsic VB code will do!!!! And it's FSO!!!
-
Oct 10th, 2001, 05:50 PM
#12
Member
*diplomatic mode* I guess its always good to have alternatives *end diplomatic mode* The FSO sucks.
-
Oct 10th, 2001, 06:02 PM
#13
I knew you would love this! Very welcome!
-
Oct 10th, 2001, 07:01 PM
#14
PowerPoster
Originally posted by filburt1
To write to a text file (this creates it if it does not exist already):
VB Code:
Dim FileHandle As Integer
Open "c:\file.txt" For Output As #FileHandle
Print #FileHandle, "Testing"
Close #FileHandle
Besides the serious one of getting the freefile didnt u also forget to declare the FileHandle as a VARIANT!! 
VB Code:
Dim FileHandle As Variant 'Only for Filburt's sake. S/be integer or long
[b]FileHandle = FreeFile[/b]
Open "c:\file.txt" For Output As #FileHandle
Print #FileHandle, "Testing"
Close #FileHandle
Regards
Stuart
-
Oct 10th, 2001, 07:03 PM
#15
Member
So it'll typecast it then into something far more superior than Variant.
-
Oct 10th, 2001, 07:12 PM
#16
Here's a quick tip nobody mentioned before:
If you're using Print to put the text into the file like this:
Print #1, MyString
..and you're wondering why there are two extra characters at the end of the file, try adding a semicolon to the end of the line:
Print #1, MyString;
The semicolon prevents VB from adding a new line to the end of the file.
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
|