Asp Dictionary in ASP
In Classic ASP (VBScript), a Dictionary object is a useful way to store key-value pairs — like an associative array or a map.
What is Dictionary in ASP?
It's a COM object provided by Microsoft Scripting Runtime.
Allows you to add, remove, and retrieve items by key.
Useful for grouping related data in memory.
How to use Dictionary in Classic ASP
1. Create Dictionary Object
<%Dim dictSet dict = Server.CreateObject("Scripting.Dictionary")%>2. Add Items
dict.Add "Name", "Alice"dict.Add "Age", 28dict.Add "Country", "USA"3. Access Items
Response.Write "Name: " & dict("Name") & "<br>"Response.Write "Age: " & dict("Age") & "<br>"Response.Write "Country: " & dict("Country") & "<br>"4. Check if Key Exists
If dict.Exists("Age") Then Response.Write "Age is " & dict("Age")Else Response.Write "Age not found."End If5. Remove Item
dict.Remove "Country"6. Loop Through Dictionary
Dim keyFor Each key In dict.Keys Response.Write key & ": " & dict(key) & "<br>"Next7. Clean Up
Set dict = NothingFull Example
<%Dim dict, keySet dict = Server.CreateObject("Scripting.Dictionary")dict.Add "Product", "Laptop"dict.Add "Price", 999.99dict.Add "Stock", 25For Each key In dict.Keys Response.Write key & " = " & dict(key) & "<br>"NextSet dict = Nothing%>If you want, I can show you examples combining Dictionary with database data or nested dictionaries!