ASP dictionary fun
Thursday, May 7th, 2009 | Programming
ASP has a lot of “interesting” features shall we say. I’ve just been working with the dictionary object which is basically an array with named items, so everything has a key and value pair.
There is a method to add elements to it which accepts variables instead of literal text strings (as you would expect of course) but it doesn’t seem to accept variables in array.
For example, this will not work…
totals.Add RSTdata(“id”), 10
Response.Write(totals(RSTdata(“id”)))
However this will work just fine…
idNumber = RSTdata(“id”)
totals.Add idNumber, 10
Response.Write(totals(idNumber))
This isn’t quite as cool as the way ASP decides the forget about some variables but only after you’ve referenced them for the first time creating a rather nice heisenbug when you put in a few print lines but never the less interesting.
ASP has a lot of “interesting” features shall we say. I’ve just been working with the dictionary object which is basically an array with named items, so everything has a key and value pair.
There is a method to add elements to it which accepts variables instead of literal text strings (as you would expect of course) but it doesn’t seem to accept variables in array.
For example, this will not work…
totals.Add RSTdata(“id”), 10
Response.Write(totals(RSTdata(“id”)))
However this will work just fine…
idNumber = RSTdata(“id”)
totals.Add idNumber, 10
Response.Write(totals(idNumber))
This isn’t quite as cool as the way ASP decides the forget about some variables but only after you’ve referenced them for the first time creating a rather nice heisenbug when you put in a few print lines but never the less interesting.