MORE INFORMATION
The maximum length for any statement in QB.EXE or BC.EXE is 255
characters, including the text in lines concatenated with the
underscore character. You can use Method 1, 2, or 3 to break up the
FIELD statement if it physically exceeds 255 characters. (The RANDOM
buffer size itself can be defined up to 32,767 bytes.)
Method 1
The easiest method is to do away with the FIELD statement altogether
and use a TYPE/END TYPE variable as your record buffer:
TYPE RecType
xname AS STRING * 30
xaddress AS STRING * 30
xcity AS STRING * 40
xstate AS STRING * 2
xzip AS STRING * 9
xmore AS STRING * 17
END TYPE
OPEN "File.DAT" FOR RANDOM AS #1 LEN = 128 ' OPEN existing file.
Max = LOF(1) / 128 ' Max=Number of records in existing file.
DIM label(Max) AS RecType
FOR i = 1 TO Max
GET #1, i, label(i)
PRINT label(i).xname
NEXT i
Method 2
You can break up the FIELD statement into more than one FIELD
statement for the same file number, using a dummy placeholder string
to account for the data previously fielded in that same file buffer:
FIELD #1, 30 AS xname$, 30 AS xaddress$, 40 AS xcity$
FIELD #1, 100 AS dummy1$, 2 AS xstate$, 9 AS xzip$
FIELD #1, 111 AS dummy2$, 17 as xmore$
In this example, dummy1$ and dummy2$ are equivalenced (overlapped)
with the total buffer defined to that point, allowing subsequent
variables to be defined further into the buffer.
Here is a trickier example, this time using a temporary placeholder
string temp$ and FIELDing a string array within a FOR ... NEXT loop:
OPEN "test.dat" FOR RANDOM AS #1 LEN = 300
DIM F$(30) ' This array will delimit the buffer in the FIELD statement.
i = 1
FOR j = 1 TO 10
FIELD #1, (j - 1) * 30 AS temp$, 10 AS F$(i), 10 AS F$(i + 1), 10 AS F$(i +
2)
i = i + 3
NEXT
LSET F$(30) = "1234567890"
LSET F$(15) = "ABCDEFGHIJ"
PUT #1, 1
CLOSE
OPEN "test.dat" FOR RANDOM AS #1 LEN = 300
i = 1
FOR j = 1 TO 10
FIELD #1, (j - 1) * 30 AS temp$, 10 AS F$(i), 10 AS F$(i + 1), 10 AS F$(i +
2)
i = i + 3
NEXT
GET #1, 1
PRINT F$(30), F$(15)
Method 3
You can FIELD the entire buffer as one string and extract pieces of
the string using the MID$ function:
OPEN "TEST" AS #1 'Assume data file TEST already has data in it.
FIELD #1, 512 AS buffer$ 'fields entire buffer in one string
GET#1,2 ' Get record number 2 (written by some other program).
'Extract the 8-byte double precision number beginning at byte 500:
component1# = CVD(MID$(buffer$,500,8))
'Extract a long integer (4 bytes) beginning at byte 508:
component2& = CVL(MID$(buffer$,508,4))
You could also write a function to extract the fields:
' Below is a function to extract a long integer from buffer$.
' FieldOffset% is the byte offset where the data starts.
' Note that buffer$ doesn't have to be a fielded string, it
' just has to be a minimum of FieldOffset% + 4 bytes long:
DEF FNL&(FieldOffset%) = CVL( MID$( buffer$, FieldOffset%, 4 ))
' Example of using the function:
component2& = FNL&(508)
Method 4
The QB.EXE environment in QuickBasic versions 4.00, 4.00b, and 4.50,
and the QBX.EXE environment in Microsoft Basic PDS versions 7.00 and
7.10 strip out the underscore (_) line-continuation character, forcing
you to scroll long lines horizontally to view and edit.
If you want to preserve the underscore characters in your source code,
you must use an editor other than QB.EXE 4.00, 4.00b, 4.50, or QBX.EXE
7.00 or 7.10. For example, you can edit with the Microsoft Editor or
Microsoft Word, and then compile the source code using BC.EXE from the
DOS prompt (or from within the Microsoft Editor, M.EXE).