943,339 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 6265
  • Java RSS
Jun 2nd, 2003
0

JScript experts - HELP needed!

Expand Post »
first post! hello all.

i'm in the process of converting some vbscript into jscript at work, and not being an expert when it comes to any sort of javascript (or c syntax generally) i am now stuck. specifically with the 'switch' statement.

the application is a server-side api that returns xml based on arguments sent to it in the querystring of its url.
e.g. /server_api.asp?action=getObjectByID&id=53

in vbscript i was grabbing all the arguments from the querystring and putting them into a scripting dictionary object called "qsDetail". then i was calling each like so... qsDetail("id") ...or whatever. iterating through each key/value pair was easy as you just use 'for...each'. obviously no such thing in jscript so i went with an enumerator object, iterating through each item and passing each pair to an associative array, like so:

Java Syntax (Toggle Plain Text)
  1. var qsDetail = [];
  2. var e = new Enumerator(Request.QueryString);
  3. for (;!e.atEnd();e.moveNext()) {
  4. var x = e.item();
  5. qsDetail[x] = Request.QueryString(x);
  6. }
so far so good. however, in the following function the 'switch' statement simply refuses to work. putting Response.write lines in to debug it, it emerges that the value "category" is indeed being passed through to the switch statement (in the example of the url above). but it just bails. if you add "default: <something>" then it runs that line instead.

Java Syntax (Toggle Plain Text)
  1. function getObjectByID() {
  2. var strSQL = "SELECT id, type, name, description FROM object WHERE id =" + qsDetail["id"];
  3. var oRs = oConn.Execute(strSQL);
  4.  
  5. if (oRs.EOF) {
  6. emptyXML();
  7. } else {
  8. outputXML = '<?xml version="1.0" ?>\n';
  9. // Loop for safety reasons, despite ID being unique
  10. while (!oRs.EOF) {
  11. switch (oRs("type")) {
  12. case "category": outputXML += processCategory(oRs("id"));
  13. case "skill": outputXML += processSkill(oRS("id"));
  14. }
  15. oRs.MoveNext;
  16. }
  17. }
  18. }
but if you replace the 'switch' statement with two 'if' statements then everything runs smoothly and it correctly goes with 'category, and the rest of the code runs fine.
Java Syntax (Toggle Plain Text)
  1. if (oRs("type") == "category") {
  2. outputXML += processCategory(oRs("id"));
  3. }
  4. if (oRs("type") == "skill") {
  5. outputXML += processSkill(oRs("id"));
  6. }
which is almost all well and good, except for ... why?!

i simply cannot see what is wrong with that 'switch' statement. in itself there appears to be nothing wrong, so i assume it has to be something in the context of the rest of the code. there are no problems relating to the DB or variables, as everything runs fine once you make the changes referred to above.

any jscript experts out there able to shed some light on this?

thanks in advance.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Ben Martin is offline Offline
2 posts
since Jun 2003
Jun 2nd, 2003
0
Re: JScript experts - HELP needed!
solved it myself. it was failed type conversion, that for some reason only affects the 'switch' statement. adding the change below now works:

Java Syntax (Toggle Plain Text)
  1. while (!oRs.EOF) {
  2. var oType = oRs("type").value;
  3. switch (oType) {

however, you have to explicitly use the 'value' property or else it will still fail.

thanks anyway guys. and hopefully this will turn out to be of use to someone else as well.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Ben Martin is offline Offline
2 posts
since Jun 2003

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: Using Java To Write MMORPG's
Next Thread in Java Forum Timeline: Help With An Online Game!





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC