Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
SubStr() and Left()
Message
From
24/08/2002 21:25:37
 
 
To
24/08/2002 20:49:40
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
00693205
Message ID:
00693369
Views:
12
Sorry Alan, you did describe the problem and my reading was at fault!

If this is repeatable then you could report it to MS (for all the good that will do for YOU).
It would also be interesting to see of the results of the SUBSTR change if you do a PADR(.........,24," ") as a test.

cheers

>Thanks Sergey and Jim, but none of this explains why Left(memofield, 24) gave the desired result using the same set of data on which SubStr(memofield, 1, 24) gave an improper (ie - blank) result. To be honest, I don't really know if an empty string was being returned, or if the field was simply being ignored.
>
>Jim, I did explain the problem. Nothing was being returned from the memo field when I used
>SubStr() while correct content was returned using Left().
>
>Remember, this was exactly the same set of data (not to mention the same application) in both cases. All I changed was that one line in the code.
>
>Alan
>
>>In order to create resulting cursor, VFP has to know the size of every field. Usually the first record of the source table is used to do that. To assure the proper size of such character field you can use PADR() function.
Select field1 + " " + field2 + " " + field3 + ;
>>  " " + field4 + " " + ;
>>  PADR(StrTran(field5, Chr(13) + Chr(10), " "), 24) from table1 ;
>>  into array aString
>>
>>>I just ran into a very odd situation today. This app is a VFP6 SP5 app. I'm converting it, but until I'm satisfied, it remains as is.
>>>
>>>Anyway, I was working on a bug in the app that seemed to affect only one of our clients. For whatever reason, the former programmer used Substr(cVar, 1, 24) to pull the first 24 characters out of a memo field in an Select - SQL call. The code concatenated 5 fields into element 1 of an array.
>>>
>>>ie:
>>>
Select field1 + " " + field2 + " " + field3 + " " + field4 + " " + ;
>>>  Substr(StrTran(field5, Chr(13) + Chr(10), " "), 1, 24) from table1 ;
>>>  into array aString
>>>
>>>There is also a where clause, but it's not significant.
>>>
>>>The bug manifested in the fact that regardless of what was in the memo field (field5), only the 1st 4 fields were showing up in the array. It was as if the 5th field always returned a blank even if the memo field contained data.
>>>
>>>I fixed the problem (don't ask me why I even tried this, because I don't have an answer), by replacing
>>>
>>>
Substr(StrTran(field5, Chr(13) + Chr(10), " "), 1, 24)
>>>with
>>>
Left(StrTran(field5, Chr(13) + Chr(10), " "), 24)
>>>
>>>Does anyone out there have even a glimmer of a clue why Left() worked when SubStr() wouldn't? Remember too, that this only makes a difference on one client's data. As far as I can tell, Substr() works fine on my test data and our other client's data. Finally, I can't see any difference in this client's data from anyone else's.
>>>
>>>Is there a difference in result between Substr(cVar, 1, 24) and Left(cVar, 24) that I don't know about?
>>>
>>>Any light shed on this would be appreciated.
>>>
>>>Alan
Previous
Reply
Map
View

Click here to load this message in the networking platform