发表评论(0)作者:不详, 平台:VB6.0+Win98, 阅读:11092, 日期:2000-10-30
Use FreeFile to Prevent File Open Conflicts
Submitted by markus@bactive.com
Both Access and VB let you hard code the file numbers when using the File Open statement. For example:
Open "myfile.txt" for Append as #1
Print #1,"a line of text"
Close #1
The problem with this method of coding is that you never know which file numbers may be in use somewhere else in your program. If you attempt to use a file number already occupied, you注释:ll get a file error. To prevent this problem, you should always use the FreeFile function. This function will return the next available file number for your use. For example:
IntFile=FreeFile()
Open "myfile.txt" for Append as #intFile
Print #intFile,"a line of text"
Close #intFile
Submitted by markus@bactive.com
Both Access and VB let you hard code the file numbers when using the File Open statement. For example:
Open "myfile.txt" for Append as #1
Print #1,"a line of text"
Close #1
The problem with this method of coding is that you never know which file numbers may be in use somewhere else in your program. If you attempt to use a file number already occupied, you注释:ll get a file error. To prevent this problem, you should always use the FreeFile function. This function will return the next available file number for your use. For example:
IntFile=FreeFile()
Open "myfile.txt" for Append as #intFile
Print #intFile,"a line of text"
Close #intFile