| | |
JScript experts - HELP needed!
![]() |
•
•
Join Date: Jun 2003
Posts: 2
Reputation:
Solved Threads: 0
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:
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.
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.
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.

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)
var qsDetail = []; var e = new Enumerator(Request.QueryString); for (;!e.atEnd();e.moveNext()) { var x = e.item(); qsDetail[x] = Request.QueryString(x); }
Java Syntax (Toggle Plain Text)
function getObjectByID() { var strSQL = "SELECT id, type, name, description FROM object WHERE id =" + qsDetail["id"]; var oRs = oConn.Execute(strSQL); if (oRs.EOF) { emptyXML(); } else { outputXML = '<?xml version="1.0" ?>\n'; // Loop for safety reasons, despite ID being unique while (!oRs.EOF) { switch (oRs("type")) { case "category": outputXML += processCategory(oRs("id")); case "skill": outputXML += processSkill(oRS("id")); } oRs.MoveNext; } } }
Java Syntax (Toggle Plain Text)
if (oRs("type") == "category") { outputXML += processCategory(oRs("id")); } if (oRs("type") == "skill") { outputXML += processSkill(oRs("id")); }
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.
•
•
Join Date: Jun 2003
Posts: 2
Reputation:
Solved Threads: 0
0
#2 Jun 2nd, 2003
solved it myself. it was failed type conversion, that for some reason only affects the 'switch' statement. adding the change below now works:
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.
Java Syntax (Toggle Plain Text)
while (!oRs.EOF) { var oType = oRs("type").value; 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.
![]() |
Similar Threads
- [MMO]Online Game Programmer needed(3 available) (Software Development Job Offers)
- SAP perm. position in Mexico (Software Development Job Offers)
- Programmer Volunteers Needed (Project Partners Wanted)
- Help needed in this script (Shell Scripting)
- Help needed in simple app while using XML,XSL (XML, XSLT and XPATH)
- help much needed !! (OS X)
Other Threads in the Java Forum
- Previous Thread: Using Java To Write MMORPG's
- Next Thread: Help With An Online Game!
| Thread Tools | Search this Thread |
-xlint actionlistener android api applet application array arrays automation bi binary blackberry block bluetooth character class client code compile compiler component consumer database desktop developmenthelp eclipse error fractal freeze ftp functiontesting game gameprogramming givemetehcodez graphics gui health html ide image integer j2me j2seprojects java javac javaee javaprojects jetbrains jni jpanel jtable julia learningresources lego linked linux list mac main map method methods mobile myregfun netbeans notdisplaying number online printf problem program project qt recursion researchinmotion rotatetext rsa scanner screen server set singleton sms sort spamblocker sql string swing system textfields threads time title tree tutorial-sample update variablebinding windows working xor





