Having thoroughly explained how this application works, this next section presents the complete code listings. So that you'll not have to type all the code manually, you'll find all the source code on the accompanying CD.
Listing 15.2 process.wmls—WMLScript for Currency Conversion Process
/*****************************************
This function calculates the currency conversion
*****************************************/
extern function convert(tAmount) {
if ( WMLBrowser.getVar("exchange_rate") == "" ) {
WMLBrowser.setVar("exchange_rate",1);
}
var origAmount = Lang.parseInt(String.trim(tAmount));
var exchRate = Lang.parseInt(String.trim(WMLBrowser.getVar("exchange_rate")));
WMLBrowser.setVar("orig_amount",tAmount);
var convertedAmount = origAmount*exchRate;
WMLBrowser.setVar("new_amount", String.toString(convertedAmount));
WMLBrowser.go("home.wml#display");
return 1;
}
/***************************************
This function sets the exchange rate
****************************************/
extern function setRate(tRate) {
WMLBrowser.setVar("exchange_rate",tRate);
WMLBrowser.go("home.wml");
return 1;
}