la! how to create a simple .txt file??
thank You in advance.
Arnas
VB6
Printable View
la! how to create a simple .txt file??
thank You in advance.
Arnas
VB6
Code:'writing or reading data to or from a text file
'open for append adds the data to the end of file
'open for input opens the file for read only
'open for output opens the file and overwrites the file
'
'
Private Sub Command1_Click()
'this is the number of your file
Dim intFilenum As Integer
'set it to the next available free number
intFilenum = FreeFile
'this is your filename
Dim strFile As String
strFile = "A:\myfile.txt"
'this is the text you want to save (textbox)(string)(etc)
Dim strText As String
strText = Text1.Text
'open the file for writing to as next freefile number
Open strFile For Append As intFilenum 'see above options
'write to the file
Write #intFilenum, strText 'to read use [input #filenum,strtext]
'close the file
Close intFilenum
End Sub
Hehe Joe, making it all hard for the guy to understand ;].
If you want it in quotes:Code:Open "C:\file.txt" For Output As #1 'create the file
Print #1, "This is what is going to be in the text file!" 'Write stuff inside the text file
Close #1 'Close the file
Code:Open "C:\file.txt" For Output As #1 'create the file
Write #1, "This is what is going to be in the text file!" 'Write stuff inside the text file
Close #1 'Close the file
You might as well teach him right the first time. ;)