Microsoft KB Archive/111991

= You receive a "Compiled code for this line too long" error message in Visual FoxPro =

Article ID: 111991

Article Last Modified on 2/12/2007

-

APPLIES TO


 * Microsoft FoxPro 2.0
 * Microsoft FoxPro 2.6a Professional Edition for Macintosh
 * Microsoft Visual FoxPro 3.0 Standard Edition
 * Microsoft Visual FoxPro 6.0 Professional Edition
 * Microsoft Visual FoxPro 7.0 Professional Edition
 * Microsoft Visual FoxPro 8.0 Professional Edition
 * Microsoft Visual FoxPro 9.0 Professional Edition

-



This article was previously published under Q111991



SYMPTOMS
Although the Microsoft FoxPro command-line length limit is 2,048 bytes, a line of compiled code cannot exceed 1,024 bytes (1 KB). This means that you can write a line of code that contains fewer than 2,048 characters that will generate a "Compiled code for this line too long" (1252) error message.

In Microsoft Visual FoxPro, the maximum number of characters per line is 8 KB. The maximum size of a line of compiled code is 4 KB. For more information about various Visual FoxPro software capacities, see the "System Capacities" topic in Visual FoxPro Help.



CAUSE
The relationship between the character representation of a command and its compiled or "tokenized" length is unpredictable.

Variable names and object references of different lengths may compile to the same number of bytes. For example, a reference to the memory variable "A" compiles to 3 bytes. However, a reference to the variable "ABCDEFGH" also compiles to 3 bytes. Similarly, a reference to the number "1" and a reference to the number "200" will each compile to 3 bytes. For this reason, shortening alias names has no effect on the length of the tokenized line.

In addition, white space and literal strings (character strings placed within quotation marks) are not tokenized. Therefore, eliminating spaces and indentation in the command line also will not affect the tokenized line length.



WORKAROUND
To work around this behavior, use one of the following methods:  Use an ON ERROR routine that traps errors 18 (Line too long), 1252 (Compiled code for this line too long), and 1812 (SQL statement too long).  Replace literal strings with variable references. This would also work for date literals (for example, {12/30/93}) and many numeric literals (for example, 4.5).

For example, in the following SELECT-SQL command, the quoted text strings, "Allied Products" and "Microsoft Corp.", cannot be tokenized any further: SELECT * FROM customer ; WHERE company = "Allied Products" or company = "Microsoft Corp." To work around this behavior, create a set of variables such as the following: m.company1="Allied Products" m.company2="Microsoft Corp." Then, change your SELECT command line to the following: SELECT * FROM customer; WHERE company=m.company1 or company=m.company2 In many cases, this command will tokenize smaller than the original command.

Note This method does not work for small integers (less than 256) because the size of a tokenized 1-byte integer is the same as the size of a tokenized variable reference. 

