asp編程工具,ASP編程語言( 二 )


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%>

推薦閱讀