Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to read price code 1

Status
Not open for further replies.

channelmaster

Technical User
Dec 9, 2001
52
PH
Hello!
How can I make my application generate price price code with a given value:
example:
volumetric && price code
1234567890 && values

v=1
o=2
l=3
u=4
m=5
e=6
t=7
r=8
i=9
c=0

when the price is saved,e.g. 1200, it should generate the code of vocc because based in above values v=1, o=2, c=0, c=0
thanks in advance
 
Hi,

Try this:
your cost is 1200(numerical) and transformed in chars is:
wcost=alltrim(str(your cost),9,2)

the values 1234567890 are transformed in chars(including decimal point). Because the decimal point is the 11 char, with no equivalent in your price code, he will be ignored in your transformation.
wvalue='1234567890.'

your price code :
wcode='volumetric'

your final code=chrtran(wcost, wvalue,wcode )='vocc'

HTH,

Bogdan
 
STRTRAN(tran(price),'0','c')
STRTRAN(tran(price),'1','v')
STRTRAN(tran(price),'2','o')
STRTRAN(tran(price),'3','l')
STRTRAN(tran(price),'4','u')
STRTRAN(tran(price),'5','m')
STRTRAN(tran(price),'6','e')
STRTRAN(tran(price),'7','t')
STRTRAN(tran(price),'8','r')
STRTRAN(tran(price),'9','i')
 
Here's how I would do it:
Code:
FUNCTION encode
LPARAMETERS vInputval,cKeyString

* If numeric, convert to string
IF VARTYPE(vInputval)='N'
    vInputval=ALLTRIM(STR(vInputval))
ENDIF

* Generate key array
DIMENSION cKey[10]
FOR i=1 to 10
    cKey[i]=SUBSTR(cKeyString,i,1)
ENDFOR

* Generate encoded value
cOutput=""
FOR i=1 to len(vInputval)
    nDigit=VAL(substr(vInputval,i,1))
    IF nDigit=0
        nDigit=10
    ENDIF
    cOutput=cOutput+cKey[nDigit]
ENDFOR

RETURN cOutput
This is yet another situation where I wish VFP would allow arrays to use subscript 0. *sigh*

Ian
 
You can solve this using a single formula:

chrtran(str(price),"1234567890","volumetric")

Good luck. Cristian
 
Thanks Cristian, your tips works very neatly and very simple. here what I did
fcode=chrtran(str(price),"1234567890","volumetric")
then, i just replace the codeprice field with fcode, wholla, simple. thanks again
rene


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top