presenting a number as a code

Questions and answers on designing your Servoy solutions, database modelling and other 'how do I do this' that don't fit in any of the other categories

presenting a number as a code

Postby Thunder » Mon Mar 21, 2005 11:22 pm

My solution calls for prices (a number) to be presented in code format. The idea is simple, X = 0, P = 1, C = 2, L = 3, G = 4 etc.

I need to be able to present prices as their equivalent code. eg, 123.00 would be PCL.00. The Filemaker solution this is replacing used 79 if statements to assign the correct code to anything up to 99,999.00. That solution has got to be the least elegant method of doing this (I was proud of it when I first made it but Servoy's magnificence requires elegance and simplicity when coding and that just wont do).

My trouble is that I am not sure how to start with getting this going. I have a feeling I need to convert number to a string and have gone so far as to assign each number to a variable as above, I'm in my Servoy Programming for Filemaker developers manual which goes on about NumToText (and its Servoy equivalent of .tostring(radix). I am just unclear on how to implement it and examples seem to be thin on the ground.

Thanks for any help you can give.

Bevil Templeton-Smith
Thunder
 
Posts: 431
Joined: Thu Apr 24, 2003 10:33 am
Location: London

Postby airmark » Mon Mar 21, 2005 11:47 pm

Bevil,

If I understand what you're trying to do, the following should work.

Code: Select all
var priceCode = number_field.toString()
priceCode = utils.stringReplace(priceCode, '1', 'P')
priceCode = utils.stringReplace(priceCode, '2', 'C')
priceCode = utils.stringReplace(priceCode, '3', 'L')
priceCode = utils.stringReplace(priceCode, '4', 'G')
price_code_field = priceCode
Greg Dendy
Airmark Industries, Inc.
325-641-1999 x.207
airmark
 
Posts: 54
Joined: Wed Oct 22, 2003 10:06 pm

Postby Thunder » Mon Mar 21, 2005 11:58 pm

Greg, that is EXACTLY what I meant and was after. Thank you very much, works perfectly and is 1000 x more elegant than my dodgy if statement.
Thunder
 
Posts: 431
Joined: Thu Apr 24, 2003 10:33 am
Location: London

Postby Thunder » Tue Mar 22, 2005 12:06 am

and may I also add...

Servoy ROCKS!!!
Thunder
 
Posts: 431
Joined: Thu Apr 24, 2003 10:33 am
Location: London


Return to Programming with Servoy

Who is online

Users browsing this forum: No registered users and 7 guests