I have to create a txt file so with some large content in VB6. Can anybody help me out on this and please tell me the references also.
TXT files are most often created by Microsoft Notepad and Apple TextEdit, which are basic text editors that come bundled with Windows and macOS, respectively.
A file with . TXT extension represents a text document that contains plain text in the form of lines. Paragraphs in a text document are recognized by carriage returns and are used for better arrangement of file contents.
This is how you can create a text file in VB6
Dim iFileNo as Integer
iFileNo = FreeFile
'open the file for writing
Open "C:\Test.txt" For Output As #iFileNo
'please note, if this file already exists it will be overwritten!
'write some example text to the file
Print #iFileNo, "first line of text"
Print #iFileNo, " second line of text"
Print #iFileNo, "" 'blank line
Print #iFileNo, "some more text!"
'close the file (if you dont do this, you wont be able to open it again!)
Close #iFileNo
Source
how large?
to keep it simple:
'1 form with:
' 1 textbox: name=Text1
' 1 command button: name=Command1
Option Explicit
Private Sub Command1_Click()
Dim intFile As Integer
Dim strFile As String
strFile = "c:\temp\file.txt" 'the file you want to save to
intFile = FreeFile
Open strFile For Output As #intFile
Print #intFile, Text1.Text 'the data you want to save
Close #intFile
End Sub
this will replace the file each time you click the command button, if you want to add to the file then you can open "for append" instead of "for output"
reference
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With