Showing posts with label array. Show all posts
Showing posts with label array. Show all posts

Friday, 6 April 2012

ASP: the dictonary object

   


I've recently worked a lot on ASP arrays. One thing that is rarely used in ASP is the dictionary object which is similar to an array but has some useful methods and properties, making it easier to manage.

The dictionary object can store information in pairs: key and item. Every key refers to an item. When we build a dictionary object we create a relation between a key and an item, so we can recall an item by its key.

An example
To create a dictionary object we simply do the following:
<%
Dim dicObj
set dicObj = Server.CreateObject("Scripting.Dictionary")
Now our object is ready to accept keys and items. In order to add them we use the .add method:
dicObj.add "one","firstItem"
dicObj.add "two","secondItem"
and so on.

Monday, 26 March 2012

ASP: dynamic variable names

   


I've been programming in ASP for such a long time that sometimes I do not really value its power. Today we are going to see an extreme example: dynamic variable names. I say "extreme" because I believe that the real use of the following code might be quite rare, however in some extreme situations, we need extreme - I know I repeat myself - solutions.
We are going to use different ASP stuff: an array and the execute and eval functions. At the same time we are going to use the split function, in order to create the array.

Wednesday, 21 March 2012

ASP: the split function and arrays

   


The ASP split function is used to - guess what - split a string into specific parts. The resulting number of items is variable and depends on how we use the function.
Basically the split function has the following syntax:
VarArray = split(string, delimiter, numberOfItems)
where:
1) string is the string to be split;
2) delimiter is the element used to determine where to split the string;
3) numberOfItems is optional and limits the number of returned items in the array.