|
List of free web storage providers. Save up to 50 GB online. |
| Active Server Pages: Dictionary |
The Dictionary object
In order to learn how Dictionary object works we will create a small
script which will translate number 1 to 10 from English to Spanish.
| translate.asp | |
| <%
SET MyDictionary=CreateObject("Scripting.Dictionary") MyDictionary.Add "one","uno"EnglishNumber="four" SpanishNumber=MyDictionary.Item (EnglishNumber) Response.Write(SpanishNumber) %> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
How the script works
| if MyDictionary.Exists ("ten")=True then
Response.Write("this key is included in the dictionary") lse Response.Write("Error: no such a key in the dictionary") end if |
Example: Translation of a number from English to Spanish
This example uses most of the elements explained above.
| translation.asp try ! | |
| <html>
<title>Page under construction</title> <body> <%
MyDictionary.Add "one","uno"EnglishNumber=request.form("EnglishNumber") Response.Write("English number: " & EnglishNumber) if MyDictionary.Exists (EnglishNumber)=True
then
<% Sub Sendform() %>
</body>
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
Example: Password protected information
In this example keys and items are used as usernames and passwords.
It is very similar to the one above.
| secretpage.asp try ! | |
| <%
if request.form="" then Sendform() else SET MyDictionary=CreateObject("Scripting.Dictionary") MyDictionary.Add "John","123" MyDictionary.Add "Peter","456" MyDictionary.Add "Anna","789" Username=request.form("Username") Password=request.form("password") if MyDictionary.Exists (Username)=True
AND Password=MyDictionary.Item (Username) then
<% Sub Sendform() %>
<% Sub SecretInfo() %>
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
|
|
Create word search puzzles with your own words
|
Tutorial home page
2008@ AspTutorial.info. All rights reserved.