I am a veteran ASP programming, spending gigabytes of time in prepearing and creating classes using vbscript. Recentely i moved to PHP, it is a greate language. But one thing strikes my mind, why should people pick up php rather than asp. Yes, php engine is greate and efficient, but i found out the key point of php, that is associative array. The asp programmer are frequently using the code snippet like below,
Redim MyList (2)
The above code is pretty simple one. I am storing the three parts of my name(First, Middle, Last in that order) . Now in my code if i want to get first name i will write as below
If i want to add some more values in the list, then when i will use them later like
address=MyList(10) it is required to remember the index number 0 or 1 or bla bla, But what if i can use the code the below way
MyList("address")="3.0 VBScript, Microsft Corp."
Yes, this is an associative array. If you know php you will see, you need to write such type of code at each 5 line.
But how could you do it in ASP. God is here, he had given us "Scripting.Dictionary" object and concept of class. You can do it folks. Lets see to do it.
What is Associative Array?
Well, even though the concept of associative array is not associated with PHP, i will go to explain that staff.
We ASP programmer all new about array, but there we need to use "index" number to access any element. Like the first sample code snippet. But in associative array, things are different. You can access any element of array not only by "index" but by "name". Like you ASP gues rmember that so much used code of "recordset" object like
rs.Open (...,"SELECT name FROM list")
Both name1 and name2 will give equal result. So one element can be access by index (0) or name ("name"). when you are bound to use only index, be sure you are using simple poor Array of ASP, but when you can access element by name and index both, you are defininely using Associative Array.
Request.Form is an associative array, if you check its type using "TypeName" method, it will show you "Dictionary" . "Scripting.Dictionary" is the entry point to us, the ASP programmer, to start using associative array.
Keep an eye on the page, you will get the code that will open up all the window of your imagination. But to keep up with your concentration take a look athe code snippet
Private Sub Class_Initialize()
Private Sub Class_Terminate()
Public Default Property Get Item(sName)
If Not dicContainer.Exists(sName) Then
dicContainer.Add sName,New AssocArray
If IsObject(dicContainer.Item(sName)) Then
Public Property Let Item(sName,vValue)
If dicContainer.Exists(sName) Then
If IsObject(vValue) Then
You can now write
Dim MyList:Set MyList=New AssocArray
The domain of using this associative array is endless. Suppose , yo are writing a order procesing page, and want to store the full details of transaction, which may contain 50 fields. Then you have to enter 50 fields in database table. But what if you store that data in associative array. And write a fewline of code which will convert the stored data in an xml formatted string, which can be stored! Similaraly, this data can be fetched later to use again.. Think..