How to create txt file

删除回忆录丶 提交于 2019-12-30 03:28:25

问题


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.


回答1:


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




回答2:


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



来源:https://stackoverflow.com/questions/21108664/how-to-create-txt-file

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!