Information générale
Catégorie:
Codage, syntaxe et commandes
I have been having problems with a function where I want to display for instance the following number 1234567 as 1 234 567. I want to do this to make a report more readable.
I came up with the following function:
PROCEDURE formatNumber(cNumber as String)
cSeperator = ' '
cNumber = PADL(ALLTRIM(cNumber), 16, cSeperator )
cString = ;
cSeperator + SUBSTR(cNumber,01,1) +;
cSeperator + SUBSTR(cNumber,02,3) +;
cSeperator + SUBSTR(cNumber,05,3) +;
cSeperator + SUBSTR(cNumber,08,3) +;
cSeperator + SUBSTR(cNumber,11,3) +;
cSeperator + SUBSTR(cNumber,14,3)
RETURN (cString)
If I try the following code:
?formatNumber('100000')
the function returns an empty code. When testing this in the debugger I function called is telling me that an empty string was passed into the function.
If I now change the function to:
PROCEDURE formatNumber(cWhatEver as String)
cSeperator = ' '
cNumber = PADL(ALLTRIM(cWhatEver ), 16, cSeperator )
cString = ;
cSeperator + SUBSTR(cWhatEver ,01,1) +;
cSeperator + SUBSTR(cWhatEver ,02,3) +;
cSeperator + SUBSTR(cWhatEver ,05,3) +;
cSeperator + SUBSTR(cWhatEver ,08,3) +;
cSeperator + SUBSTR(cWhatEver ,11,3) +;
cSeperator + SUBSTR(cWhatEver ,14,3)
RETURN (cString)
and try again the '100000' is properly passed into the function.
Why is this? Is the cNumber reserved for other uses?
I'm doing this with VFP7.
Regards,
Ron
Suivant
Répondre
Voir le fil de ce thread
Voir le fil de ce thread à partir de ce message seulement
Voir tous les messages de ce thread
Voir tous les messages de ce thread à partir de ce message seulement