LOF: Difference between revisions
Jump to navigation
Jump to search
Navigation:
Main Page with Articles and Tutorials
Keyword Reference - Alphabetical
Keyword Reference - By usage
Report a broken link
(Add information on HTTP handles) |
No edit summary |
||
(4 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
The | The '''LOF''' function is used to find the length of an [[OPEN]] file in bytes, or content length of an HTTP response. | ||
Line 19: | Line 18: | ||
** [[LOF]] returns the length listed in the Content-Length header of the HTTP response. | ** [[LOF]] returns the length listed in the Content-Length header of the HTTP response. | ||
** If no Content-Length header was provided on the HTTP response, then [[LOF]] return -1 | ** If no Content-Length header was provided on the HTTP response, then [[LOF]] return -1 | ||
{{PageExamples}} | {{PageExamples}} | ||
;Example:Finding the number of records in a RANDOM file using a [[TYPE]] variable. | |||
{{CodeStart}} | {{CodeStart}} | ||
OPEN file$ FOR RANDOM AS #1 LEN = {{Cl|LEN}}(Type_variable) | {{Cl|OPEN}} file$ {{Cl|FOR}} {{Cl|RANDOM}} {{Cl|AS}} #1 {{Cl|LEN}} = {{Cl|LEN}}(Type_variable) | ||
NumRecords% = {{Cl|LOF}}(1) \ RecordLEN% | NumRecords% = {{Cl|LOF}}(1) \ RecordLEN% | ||
{{CodeEnd}} | {{CodeEnd}} | ||
---- | |||
;Example:Reading the Content length of an HTTP response | |||
{{CodeStart}} | {{CodeStart}} | ||
{{Cl|$UNSTABLE}}: | {{Cl|$UNSTABLE}}:HTTP | ||
h& = {{Cl|_OPENCLIENT}}("HTTP:https://qb64phoenix.com") | h& = {{Cl|_OPENCLIENT}}("HTTP:<nowiki>https://qb64phoenix.com</nowiki>") | ||
{{Cl|PRINT}} {{Cl|LOF}}(h&) | {{Cl|PRINT}} {{Cl|LOF}}(h&) | ||
{{CodeEnd}} | {{CodeEnd}} | ||
{{PageSeeAlso}} | {{PageSeeAlso}} |
Latest revision as of 18:22, 30 January 2023
The LOF function is used to find the length of an OPEN file in bytes, or content length of an HTTP response.
Syntax
Description
- For regular OPENed files:
- LOF returns the number of bytes in an OPENed designated fileNumber. File is empty if it returns 0.
- fileNumber is the number of the opened file. # is not required.
- Often used to determine the number of records in a RANDOM access file.
- Can also be used to avoid reading an empty file, which would create an error.
- LOF in QB64 can return up to 9 GB (9,223,372,036 bytes) file sizes.
- For HTTP handles opened using _OPENCLIENT:
Examples
- Example
- Finding the number of records in a RANDOM file using a TYPE variable.
OPEN file$ FOR RANDOM AS #1 LEN = LEN(Type_variable) NumRecords% = LOF(1) \ RecordLEN% |
- Example
- Reading the Content length of an HTTP response
$UNSTABLE:HTTP h& = _OPENCLIENT("HTTP:https://qb64phoenix.com") PRINT LOF(h&) |
See also