- ·上一篇文章:一种效率极高的分类算法(转--非常好,帮助很大对于想做好asp的朋友)
- ·下一篇文章:实现文件下载而不是由ie打开的代码
ASP在Scripting.Dictionary对象的作用是什么?
"<OPTION>" & objItem<br>
Next<br>
%><br>
</SELECT> ") = "<br>
<INPUT TYPE="TEXT" NAME="txtChangeKey" SIZE="15" VALUE="New Key Name"> "<br>
<BR><br>
…<br>
… Other controls go here …<br>
…<br>
</FORM><br>
…<br>
4. 使用Dictionary的属性和方法<br>
在“Scription.Dictionary Object”页面,点击用来检查并改变条目的Key属性的按钮,如图5-5所示:<br>
<br>
图5-5 使用Dictionary的Key属性<br>
把窗体再次提交给页面。该页面包含一个脚本段,检查被点击的按钮的值。它通过在Resquest.Form集合里查找按钮的名字来断定单击的是哪个按钮。如果发现一个对应于cmdChangKey的值,则从列表中或文本框中得到相应的值并用来改变Key属性:<br>
…<br>
''look for a command sent from the FORM section buttons<br>
If Len(Request.Form("cmdChangeKey")) Then<br>
strKeyName = Request.Form("lstChangeKey") ''Existing key from list box<br>
strNewKey = Request.Form("txtChangeKey") ''New key value from text box<br>
objMyData.Key(strKeyName) = strNewKey ''Set key property of this item<br>
End If<br>
…<br>
页面重新载入后,在Dictionary的内容列表里能看到相应的结果,如图5-6所示:<br>
<br>
图5-6 页面重载后的结果<br>
页面的其余代码用来设定一个条目的Item属性,或者执行Dictionary对象的方法。下面是这些操作的代码,每段代码与演示Key属性的代码非常类似。每次都将结果显示在Dictionary的内容列表中:<br>
…<br>
If Len(Request.Form("cmdChangeItem")) Then<br>
strKeyName = Request.Form("lstChangeItem") ''Existing key from list box<br>
strNewValue = Request.Form("txtChangeItem") ''New item value from text box<br>
objMyData.Item(strKeyName) = strNewValue ''Set the Item property<br>
End If<br>
<br>
If Len(Request.Form("cmdAdd")) Then<br>
strKeyName = Request.Form("txtAddKey") ''New key value from text box<br>
strItemValue = Request.Form("txtAddItem") ''New item value from text box<br>
objMyData.Add strKeyName, strItemValue ''Execute the Add method<br>
End If<br>
<br>
If Len(Request.Form("cmdRemove")) Then<br>
strKeyName = Request.Form("lstRemove") ''Existion key from list box<br>
objMyData.Remove strKeyName ''Execute the Remove method<br>
End If<br>
<br>
If Len(Request.Form("cmdRemoveAll")) Then<br>
objMyData.RemoveAll ''Execute the RemoveAll method<br>
End If<br>
…<br>
例如,如果现在点击Add方法的按钮,在Dictionary的内容列表里将增加一个新的条目,如图5-7所示:<br>
<br>
图5-7 增加一个新方法<br>
结果如图5-8所示:<br>
<br>
图5-8 Add方法的结果<br>
可以在这个页面中试验Dictionary对象的属性和方法,你将会发现什么因素及在什么环境下能引起Dictionary对象错误。例如,尝试用与已经存在的一个条目相同的键值增加一个条目,看看会出现什么结果。
做人要厚道,请注明转自chinazhan中国站长(www.ChinaZhan.com)。
Next<br>
%><br>
</SELECT> ") = "<br>
<INPUT TYPE="TEXT" NAME="txtChangeKey" SIZE="15" VALUE="New Key Name"> "<br>
<BR><br>
…<br>
… Other controls go here …<br>
…<br>
</FORM><br>
…<br>
4. 使用Dictionary的属性和方法<br>
在“Scription.Dictionary Object”页面,点击用来检查并改变条目的Key属性的按钮,如图5-5所示:<br>
<br>
图5-5 使用Dictionary的Key属性<br>
把窗体再次提交给页面。该页面包含一个脚本段,检查被点击的按钮的值。它通过在Resquest.Form集合里查找按钮的名字来断定单击的是哪个按钮。如果发现一个对应于cmdChangKey的值,则从列表中或文本框中得到相应的值并用来改变Key属性:<br>
…<br>
''look for a command sent from the FORM section buttons<br>
If Len(Request.Form("cmdChangeKey")) Then<br>
strKeyName = Request.Form("lstChangeKey") ''Existing key from list box<br>
strNewKey = Request.Form("txtChangeKey") ''New key value from text box<br>
objMyData.Key(strKeyName) = strNewKey ''Set key property of this item<br>
End If<br>
…<br>
页面重新载入后,在Dictionary的内容列表里能看到相应的结果,如图5-6所示:<br>
<br>
图5-6 页面重载后的结果<br>
页面的其余代码用来设定一个条目的Item属性,或者执行Dictionary对象的方法。下面是这些操作的代码,每段代码与演示Key属性的代码非常类似。每次都将结果显示在Dictionary的内容列表中:<br>
…<br>
If Len(Request.Form("cmdChangeItem")) Then<br>
strKeyName = Request.Form("lstChangeItem") ''Existing key from list box<br>
strNewValue = Request.Form("txtChangeItem") ''New item value from text box<br>
objMyData.Item(strKeyName) = strNewValue ''Set the Item property<br>
End If<br>
<br>
If Len(Request.Form("cmdAdd")) Then<br>
strKeyName = Request.Form("txtAddKey") ''New key value from text box<br>
strItemValue = Request.Form("txtAddItem") ''New item value from text box<br>
objMyData.Add strKeyName, strItemValue ''Execute the Add method<br>
End If<br>
<br>
If Len(Request.Form("cmdRemove")) Then<br>
strKeyName = Request.Form("lstRemove") ''Existion key from list box<br>
objMyData.Remove strKeyName ''Execute the Remove method<br>
End If<br>
<br>
If Len(Request.Form("cmdRemoveAll")) Then<br>
objMyData.RemoveAll ''Execute the RemoveAll method<br>
End If<br>
…<br>
例如,如果现在点击Add方法的按钮,在Dictionary的内容列表里将增加一个新的条目,如图5-7所示:<br>
<br>
图5-7 增加一个新方法<br>
结果如图5-8所示:<br>
<br>
图5-8 Add方法的结果<br>
可以在这个页面中试验Dictionary对象的属性和方法,你将会发现什么因素及在什么环境下能引起Dictionary对象错误。例如,尝试用与已经存在的一个条目相同的键值增加一个条目,看看会出现什么结果。
做人要厚道,请注明转自chinazhan中国站长(www.ChinaZhan.com)。
