Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
SubStr() and Left()
Message
 
 
À
23/08/2002 20:01:26
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Divers
Thread ID:
00693205
Message ID:
00693212
Vues:
12
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
--sb--
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform