Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
The number in Replicate creates a problem
Message
 
 
To
05/04/2022 01:33:51
John Ryan
Captain-Cooker Appreciation Society
Taumata Whakatangi ..., New Zealand
General information
Forum:
Visual FoxPro
Category:
Troubleshooting
Miscellaneous
Thread ID:
01684050
Message ID:
01684060
Views:
34
>Hi Dmitry,
>
>>>If I change the 10 in the above REPLICATE with 15, no error.
>>>
>>>REPLICATE(' ',15-LEN(ALLTRIM(REFERENCE)))
>>>
>
>Weird errors can occur in VFP SQL Select when a selected expression has variable length. Basically the first encountered instance sets the size of the result field.
>
>Example: if the first selected ALLTRIM(REFERENCE) length is 10 chars, then
>
REPLICATE(' ',10-LEN(ALLTRIM(REFERENCE)))
yields
REPLICATE(' ',0)
which is a zero-length string.
>
>However, in SQL it appears to generate a one-character result field, presumably because 0 length fields cannot exist. I wonder whether this anomaly is part of the problem, since one character is too short for even one   and to be useful you'd need that result to be long enough for the shortest REFERENCE.
>
>If the code used to work, perhaps that was because shorter REFERENCE is encountered first. Was the resultset ordered?
>
>Increasing to 15 may avoid the issue because now the result field is at least 6*5=30 chars rather than an unexpected 1 character.
>
>If this is the explanation, then ordering the resultset or
PADR(REPLICATE(' ',10-LEN(ALLTRIM(REFERENCE))),60)
should prevent the issue.

Hi John,
The result is not ordered.
Your suggestion with the PADR() around the REPLICATE, gives the same error. The number (10 or 15) has to match the field length.
"The creative process is nothing but a series of crises." Isaac Bashevis Singer
"My experience is that as soon as people are old enough to know better, they don't know anything at all." Oscar Wilde
"If a nation values anything more than freedom, it will lose its freedom; and the irony of it is that if it is comfort or money that it values more, it will lose that too." W.Somerset Maugham
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform