Revision history for KeyPgFreefile
Revision [24840]
Last edited on 2021-01-10 09:16:56 by fxm [additional description in case of multi-threading conflict]Additions:
**""-""** In case of potential conflict with other threads, this non-breaking '##**Freefile**...[[KeyPgOpen|Open]]##' sequence must additionally be considered as a critical section of code and therefore must be protected, for example by mutual exclusion (using a mutex locking).
Deletions:
Revision [24839]
Edited on 2021-01-09 13:36:17 by fxm [additional description in case of multi-threading conflict]Additions:
**""-""** In case of potential conflict with other threads, this non-breaking '##**Freefile**...[[KeyPgOpen|Open]]##' sequence must additionally be considered as a critical section of code and therefore must be protected for example by mutual exclusion (using a mutex locking).
Deletions:
Revision [24810]
Edited on 2020-12-31 13:08:46 by fxm [additional description in case of multi-threading conflict]Additions:
##**Freefile**## will always return the smallest free file number. The file number returned by ##**Freefile**## will not change until that file number is ##[[KeyPgOpen|Open]]##ed, or until a smaller file number is ##[[KeyPgClose|Close]]##d:
**""-""** For this reason, it is wise to use ##**Freefile**## immediately before its corresponding ##[[KeyPgOpen|Open]]##, to ensure that the same file number is not returned and opened elsewhere first.
**""-""** In case of potential conflict with other threads, this non-breaking '##**Freefile**...[[KeyPgOpen|Open]]##' sequence must additionally be considered as a critical section of code and therefore must be protected by mutual exclusion (using a mutex locking).
**""-""** For this reason, it is wise to use ##**Freefile**## immediately before its corresponding ##[[KeyPgOpen|Open]]##, to ensure that the same file number is not returned and opened elsewhere first.
**""-""** In case of potential conflict with other threads, this non-breaking '##**Freefile**...[[KeyPgOpen|Open]]##' sequence must additionally be considered as a critical section of code and therefore must be protected by mutual exclusion (using a mutex locking).
Deletions:
Additions:
- ##[[KeyPgFileattr|FileAttr]]##
Revision [21825]
Edited on 2017-08-19 18:13:54 by MrSwiss [Replaced 'integer' with 'long' in Example Code (proper FreeFile return)]Additions:
Dim buffer As String, f as long
dim as long fr, fs
dim as long fr, fs
dim as long fr, fs
dim as long fr, fs
Deletions:
dim fr as integer, fs as integer
dim fr as integer, fs as integer
Additions:
Additions:
[[KeyPgDeclare|declare]] [[KeyPgFunction|function]] **Freefile** ( ) [[KeyPgAs|as]] [[KeyPgLong|long]]
Returns the number of the next free file number with valid values ##1## to ##255##, or ##0## if there are already 255 files opened. This value is a required argument to ##[[KeyPgOpen|Open]]## a file. ##**Freefile**## is useful when opening files in complex programs where the programmer can't keep track of the used file numbers.
##**Freefile**## will always return the smallest free file number. The file number returned by ##**Freefile**## will not change until that file number is ##[[KeyPgOpen|Open]]##ed, or until a smaller file number is ##[[KeyPgClose|Close]]##d. For this reason, it is wise to use ##**Freefile**## immediately before its corresponding ##[[KeyPgOpen|Open]]##, to ensure that the file number is not returned and opened elsewhere first.
When using multiple ##**Freefile**## statements, ##**Freefile**## should be used immediately before the ##[[KeyPgOpen|Open]]## statement:
- ##[[KeyPgOpen|Open]]##
- ##[[KeyPgPutfileio|Put (File I/O)]]##
- ##[[KeyPgGetfileio|Get (File I/O)]]##
Returns the number of the next free file number with valid values ##1## to ##255##, or ##0## if there are already 255 files opened. This value is a required argument to ##[[KeyPgOpen|Open]]## a file. ##**Freefile**## is useful when opening files in complex programs where the programmer can't keep track of the used file numbers.
##**Freefile**## will always return the smallest free file number. The file number returned by ##**Freefile**## will not change until that file number is ##[[KeyPgOpen|Open]]##ed, or until a smaller file number is ##[[KeyPgClose|Close]]##d. For this reason, it is wise to use ##**Freefile**## immediately before its corresponding ##[[KeyPgOpen|Open]]##, to ensure that the file number is not returned and opened elsewhere first.
When using multiple ##**Freefile**## statements, ##**Freefile**## should be used immediately before the ##[[KeyPgOpen|Open]]## statement:
- ##[[KeyPgOpen|Open]]##
- ##[[KeyPgPutfileio|Put (File I/O)]]##
- ##[[KeyPgGetfileio|Get (File I/O)]]##
Deletions:
Returns the number of the next free file number with valid values ##1## to ##255##, or ##0## if there are already 255 files opened. This value is a required argument to ##[[KeyPgOpen Open]]## a file. ##**Freefile**## is useful when opening files in complex programs where the programmer can't keep track of the used file numbers.
##**Freefile**## will always return the smallest free file number. The file number returned by ##**Freefile**## will not change until that file number is ##[[KeyPgOpen Open]]##ed, or until a smaller file number is ##[[KeyPgClose Close]]##d. For this reason, it is wise to use ##**Freefile**## immediately before its corresponding ##[[KeyPgOpen Open]]##, to ensure that the file number is not returned and opened elsewhere first.
When using multiple ##**Freefile**## statements, ##**Freefile**## should be used immediately before the ##[[KeyPgOpen Open]]## statement:
- ##[[KeyPgOpen Open]]##
- ##[[KeyPgPutfileio Put (File I/O)]]##
- ##[[KeyPgGetfileio Get (File I/O)]]##
Additions:
[[KeyPgDeclare declare]] [[KeyPgFunction function]] **Freefile** ( ) [[KeyPgAs as]] [[KeyPgLong long]]
Deletions:
Additions:
' The WRONG way:
Deletions:
Additions:
Returns the number of the next free file number with valid values ##1## to ##255##, or ##0## if there are already 255 files opened. This value is a required argument to ##[[KeyPgOpen Open]]## a file. ##**Freefile**## is useful when opening files in complex programs where the programmer can't keep track of the used file numbers.
Make sure to always close files when no longer needed, otherwise you will get a file number leak, and won't be able to open any files anymore after 255 filenumbers are exhausted while your program is running.
##**Freefile**## will always return the smallest free file number. The file number returned by ##**Freefile**## will not change until that file number is ##[[KeyPgOpen Open]]##ed, or until a smaller file number is ##[[KeyPgClose Close]]##d. For this reason, it is wise to use ##**Freefile**## immediately before its corresponding ##[[KeyPgOpen Open]]##, to ensure that the file number is not returned and opened elsewhere first.
' The CORRECT way:
OPEN "File2" FOR INPUT AS #fs
fs = FREEFILE '' fs has taken the same file number as fr
OPEN "file2" FOR INPUT AS #fs '' error: file number already opened
Make sure to always close files when no longer needed, otherwise you will get a file number leak, and won't be able to open any files anymore after 255 filenumbers are exhausted while your program is running.
##**Freefile**## will always return the smallest free file number. The file number returned by ##**Freefile**## will not change until that file number is ##[[KeyPgOpen Open]]##ed, or until a smaller file number is ##[[KeyPgClose Close]]##d. For this reason, it is wise to use ##**Freefile**## immediately before its corresponding ##[[KeyPgOpen Open]]##, to ensure that the file number is not returned and opened elsewhere first.
' The CORRECT way:
OPEN "File2" FOR INPUT AS #fs
fs = FREEFILE '' fs has taken the same file number as fr
OPEN "file2" FOR INPUT AS #fs '' error: file number already opened
Deletions:
' The CORRECT WAY:
OPEN "file2" FOR INPUT AS #fs
OPEN "file2" FOR INPUT AS #fs
Revision [14880]
Edited on 2010-10-16 21:38:04 by CountingPine [ZERO to zero/0, Close *#f* in example, formatting]Additions:
The next available file number, if any, otherwise zero (##0##).
Returns the number of the next free file number with valid values ##1## to ##255##, or ##0## if there are already 255 files opened. This value is a required argument to ##[[KeyPgOpen Open]]## a file. ##**Freefile**## is useful when opening files in complex programs where the programmer can't keep track of the used file numbers. Make sure to always close files when no longer needed, otherwise you will get a filenumber leak, and won't be able to open any files anymore after 255 filenumbers are exhausted while your program is running. All opened files will get closed automatically at program termination.
Close #f
Returns the number of the next free file number with valid values ##1## to ##255##, or ##0## if there are already 255 files opened. This value is a required argument to ##[[KeyPgOpen Open]]## a file. ##**Freefile**## is useful when opening files in complex programs where the programmer can't keep track of the used file numbers. Make sure to always close files when no longer needed, otherwise you will get a filenumber leak, and won't be able to open any files anymore after 255 filenumbers are exhausted while your program is running. All opened files will get closed automatically at program termination.
Close #f
Deletions:
Returns the number of the next free file number with valid values 1 to 255, or ZERO if there are already 255 files opened. This value is a required argument to ##[[KeyPgOpen Open]]## a file. ##**Freefile**## is useful when opening files in complex programs where the programmer can't keep track of the used file numbers. Make sure to always close files when no longer needed, otherwise you will get a filenumber leak, and won't be able to open any files anymore after 255 filenumbers are exhausted while your program is running. All opened files will get closed automatically at program termination.
Close
Additions:
The next available file number or ZERO.
Returns the number of the next free file number with valid values 1 to 255, or ZERO if there are already 255 files opened. This value is a required argument to ##[[KeyPgOpen Open]]## a file. ##**Freefile**## is useful when opening files in complex programs where the programmer can't keep track of the used file numbers. Make sure to always close files when no longer needed, otherwise you will get a filenumber leak, and won't be able to open any files anymore after 255 filenumbers are exhausted while your program is running. All opened files will get closed automatically at program termination.
- Besides ""FreeBASIC's"" limit of 255 files per program opened at same time, there is an OS limit of total amount of opened files, but usually you won't touch it except in DOS, where the limit may be as low as 15 files total.
Returns the number of the next free file number with valid values 1 to 255, or ZERO if there are already 255 files opened. This value is a required argument to ##[[KeyPgOpen Open]]## a file. ##**Freefile**## is useful when opening files in complex programs where the programmer can't keep track of the used file numbers. Make sure to always close files when no longer needed, otherwise you will get a filenumber leak, and won't be able to open any files anymore after 255 filenumbers are exhausted while your program is running. All opened files will get closed automatically at program termination.
- Besides ""FreeBASIC's"" limit of 255 files per program opened at same time, there is an OS limit of total amount of opened files, but usually you won't touch it except in DOS, where the limit may be as low as 15 files total.
Deletions:
Returns the number of the next free file number with valid values 1 to 254, or ZERO if there are already 254 files opened. This value is a required argument to ##[[KeyPgOpen Open]]## a file. ##**Freefile**## is useful when opening files in complex programs where the programmer can't keep track of the used file numbers. Make sure to always close files when no longer needed, otherwise you will get a filenumber leak, and won't be able to open any files anymore after 254 filenumbers are exhausted while your program is running. All opened files will get closed automatically at program termination.
- Besides ""FreeBASIC's"" limit of 254 files per program opened at same time, there is an OS limit of total amount of opened files, but usually you won't touch it except in DOS, where the limit may be as low as 15 files total.
Additions:
Returns the number of the next free file number with valid values 1 to 254, or ZERO if there are already 254 files opened. This value is a required argument to ##[[KeyPgOpen Open]]## a file. ##**Freefile**## is useful when opening files in complex programs where the programmer can't keep track of the used file numbers. Make sure to always close files when no longer needed, otherwise you will get a filenumber leak, and won't be able to open any files anymore after 254 filenumbers are exhausted while your program is running. All opened files will get closed automatically at program termination.
- Besides ""FreeBASIC's"" limit of 254 files per program opened at same time, there is an OS limit of total amount of opened files, but usually you won't touch it except in DOS, where the limit may be as low as 15 files total.
- Besides ""FreeBASIC's"" limit of 254 files per program opened at same time, there is an OS limit of total amount of opened files, but usually you won't touch it except in DOS, where the limit may be as low as 15 files total.