5.遍历Dictionary
研究Dictionary时,有两个方法和一个属性需要特别注意,它们允许我们遍历存储在Dictionary里的所有键/条目对 。Items方法用一个一维数组的形式返回Dictionary里所有的条目数据,而keys方法用一个一维数组返回所有已存在的键值 。可以使用Count属性得到键或条目的数量 。
例如,可以使用下列代码得到名称为objMyData的Dictionary中所有的键和条目值 。注意,虽然Count属性保存了在Dictionary里的键/条目数量,但VBScript和JScript的数组总是从下标0开始的 。因此,数组下标应从0到Count-1 。
‘In _VBScript:
arrKeys = objMyData.Keys‘Get all the keys into an array
arrItems = objMyData.Items‘Get all the items into an array
For intLoop = 0 To objMyData.Count –1‘Iterate through the array
StrThisKey = arrKeys(intLoop)‘This is the key value
StrThisItem = arrItems(intLoop)‘This is the item (data) value
Next
// In JScript
// Get VB-style arrays using the Keys() and Items() methods
var arrKeys = new VBArray(objMyData.Keys()).toArray();
var arrItems = new VBArray(objMyData.Items()).toArray();
for (intLoop = 0; intLoop < objMyData.Count; intLoop++) {
// Iterate through the arrays
strThisKey = arrKeys[intLoop];// This is the key value
strThisItem = arrItems[intLoop];// This is the item (data) value
}
在VBScript里也可以使用For Each … Next语句完成同样的功能:
‘ Iterate the dictionary as a collection in VBScript
For Each objItem in arrItems
Response.Write objItem & “ = “ & arrItems(objItem) & “
”
Next
ASP编程中采用哪种语言:
1、ASP编程中服务器默认的脚本语言是VBScript,因为VB是微软的原因,自然要推广自己的产品 。
2、另外javascript同样也可以作为服务器脚本语言 。在一个ASP页面中,你可以选择其中的一种,也可以同时使用两种,只是这样页面被解释的速度会下降 。
3、ASP编程中客户端采用的脚本语言是JavaScript 。其实也可以用VBscript,但是因为VBscript并不是所有浏览器都支持,比如NS 。所以我们一般就会选择JavaScript了 。
ASP编写一个程序:
<%Dim Adm_Account,Adm_PwdSet Adm_Account = Trim(Request.Form("Adm_Account"))Set Adm_Pwd = Trim(Request.Form("Adm_Pwd"))If Adm_Account = "" OR Adm_Pwd = "" ThenResponse.Write "
用户名或密码不能为空!请返回后重新输入
"Else%><%Dim rs Set rs = Server.CreateObject("adodb.recordset")rs.open "select Adm_Accountfrom AdminInfo where Adm_Account = '"&Adm_Account&"' and Adm_Pwd = '"&Adm_Pwd&"'",cnif not rs.eof thenResponse.Write "登录成功!
" session("Adm_Name")=rs(Adm_Account)Response.Redirect("Index.htm")elseResponse.Write "登陆失败!
"end if %><% rs.close set rs = nothing END IF %><!--#include file="../Include/cnClose.asp" --><!--#include file="Login.asp" -->还需要按你的路径修改路径参数~
简单ASP编程:
【asp编程工具,ASP编程语言】点击这里获取信息用户信息姓名:<%response.write(request("username"))%>
性别:<%response.write(request("sex"))%>
年龄:<%response.write(request("age"))%>
爱好:<%for i=1 to request.QueryString("hobby").countresponse.write(request.QueryString("hobby")(i))response.write("")next%>
推荐阅读
- asp源码
- aspect抛光面膜功效
- aspx打不开怎么办 aspx怎么打开
- yearn和aspire的区别牛津 yearn和aspire的区别
- aspx文件怎么打开 如何打开aspx文件
- asprey是什么品牌 asprey是什么意思