Writing A Multi-Currency Converter Using WMLScript (cont.)
by Wei Meng LEE
Debugging The WMLScript
One of the difficulties that I found when coding this application is troubleshooting your WMLScript when you are faced with some problems.
Since I am using the UP.Simulator for this application, I naturally turn to the Phone Information window for help when it comes to debugging.
Apart from some of the syntax errors that would quite often emerge, another tricky problem is with caching. You need to ensure that
the WMLScript file is cached and used at the right time.
Let's discuss the first problem: Syntax Error. Syntax error can be detected easily using the Phone Information window.
For example, assume we have the following error in our WMLScript program:
var USD =<% rs.Find "Currency = 'USD'"
%> // missing ";"
The above error is going to generate an error in the compilation process and the following deck would be shown:
Looking into the Phone Information window reveals the following source of error:
(25) : error: syntax error at "var" missing ;
The second problem is trickier. You want to know whether you have set the expiration date of the WMLScript correctly. For instance, when
you load the application for the first time at 7.30am, the WMLScript should expire in 30 minutes time. To check that, the UP.Simulator
provides an option for you to display the cache information of the browser. To display the cache information, press the F6 function key
or click on Info->Cache.
The cache information would then be displayed in the Phone Information window:
Notice that the Calculate.asp document (generating the WMLScript file) has a TTL (Time-To-Live) of 30 minutes. This indicates that the
WMLScript will expire in 30 minutes time (since loading time is 7.30am).
DumpCacheEntries By Request
Flags: R=Must-Revalidate I=InUse O=OutOfDate C=InChannel
Types: B=Bitmap !=BOGUS W=WML S=WMLScript C=Chan
URLM DOCM FLAG T PR TTL URLS
01588/2 01600/2 S 1 30m HTTP://LOCALHOST/Calculate.asp
01564/9 01572/3 W 1 29d HTTP://LOCALHOST/currency.wml
Once the application is loaded, the WMLScript in the cache would be used if the application is accessed between 7.30am to 8am. This is
reflected in the Phone Information when the application is run again:
When the same application is accessed after 8am, the WMLScript would then have expired and a reload is necessary. To be certain
that the WMLScript is reloaded, check the Phone Information window to see that the WMLScript is recompiled:
HTTP GET Request: HTTP://LOCALHOST/Calculate.asp
----------------- DATA SIZE ------------------------
Uncompiled data from HTTP is 860 bytes.
...found Content-Type: text/vnd.wap.wmlscript.
[xlateWMLScript] [unknown subscriber] Compiling WMLScript[xlateWMLScript] WMLScr
ipt was successfulCompiled WAP binary is 278 bytes.
Now, during the debugging stage you might be tempted to forward your system clock to see the expiration effect of the WMLScript. However, this
does not work. For example, if you load the application at 7.45am, the TTL of the WMLScript file would be 15 minutes. If you now adjust
your time to 8.00am, the WMLScript would still be loaded from cache. This is because the expiration of the WMLScript works based on the "count-down" effect.
The correct way to do this is to set the clock to say 7.58 and load the application. After that, wait for about 5 minutes before loading
the application again. This time round, the WMLScript would expire!
Next: Lessons Learned