Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
The number in Replicate creates a problem
Message
From
05/04/2022 12:37:55
Lutz Scheffler (Online)
Lutz Scheffler Software Ingenieurbüro
Dresden, Germany
 
General information
Forum:
Visual FoxPro
Category:
Troubleshooting
Miscellaneous
Thread ID:
01684050
Message ID:
01684075
Views:
44
Likes (2)
Dimitry,

Run the code from message#01684073. Watch your screen. Your REPLICATE(' ',10-LEN(ALLTRIM(REFERENCE))) is like REPLICATE(' ',10-LEN(REFERENCE)) for the determination of field length. This internally runs BEFORE filling the fields.

To make at as clear as possible how SELECT SQL works
1. It does a blind run to figure out field types and length. This run is not visible and gives no record in return. This run ignores ALLTRIM() So SELECT REPLICATE(' ',10-LEN(ALLTRIM(REFERENCE))) AS cField FROM .. is executed like SELECT REPLICATE(' ',10-LEN(REFERENCE)) AS cField FROM .. 10-LEN(REFERENCE) is like 10-15; equals -5
2. It runs to fill the result records, here the ALLTRIM() will be respected.
So your code errors out on point 1.

IOW. It does not matter how many signs you have in any record in the field REFERENCE. As long as the field length itself is greater then 10, your code must fail.

Just an other example
CREA CURSOR mycur (i1 I, c1 c(10))
INSERT INTO mycur VALUES (0,'')
INSERT INTO mycur VALUES (0,'c')
INSERT INTO mycur VALUES (0,'cc')
SELE ALLTRIM(c1) AS c1 FROM mycur INTO CURSOR cmycur
?LEN(cmycur.c1)
Why do you think cmycur.c1 has length 10? Because of the blind run.
Words are given to man to enable him to conceal his true feelings.
Charles Maurice de Talleyrand-Périgord

Weeks of programming can save you hours of planning.

Off

There is no place like [::1]
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform