•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the Java section within the Software Development category of DaniWeb, a massive community of 391,550 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,583 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Java advertiser: Lunarpages Java Web Hosting
Views: 5121 | Replies: 1
![]() |
•
•
Join Date: Jun 2003
Posts: 2
Reputation:
Rep Power: 0
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:
var qsDetail = [];
var e = new Enumerator(Request.QueryString);
for (;!e.atEnd();e.moveNext()) {
var x = e.item();
qsDetail[x] = Request.QueryString(x);
}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;
}
}
}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:
Rep Power: 0
Solved Threads: 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.
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.
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb Java Marketplace
- Dreaded IDE #1 ERROR info. (Storage)
- Help needed in simple app while using XML,XSL (XML, XSLT and XPATH)
- Why are there so many languages? (Computer Science and Software Design)
- VB.Net experts: I need some help (VB.NET)
- Jscript Replace Function (ASP)
- help much needed !! (OS X)
Other Threads in the Java Forum
- Previous Thread: Using Java To Write MMORPG's
- Next Thread: Filling a ComboBox....


Linear Mode