asp For Each語句執行個體

來源:互聯網
上載者:User

 
<html>
<head>
<title>for each語句執行個體example27</title>
</head>
<body>
<form method="post" action="example27.asp" name = form1>
 <p align="center">請輸入電子郵箱:<input type="text" name="email" size="20" value=<%=request.form("email")%>></p>
 <p align="center"><input type="submit" value="確定" name="submit"></p>
</form>
<%
 if request.form("submit")="確定" then
  email=request.form("email")       '讀取輸入的字串
  names=split(email,"@")        'split函數是將字串用指定的字元分割成多個子字串,並將這些子字串儲存在一維數組中
  if ubound(names)<>1 then       'ubound函數返回數組的最大下標
   response.write("<script>alert('郵件格式錯誤!')</script>")  '給出提示
   response.end        '結束運行asp程式
  end if
  for each name in names        'for each迴圈語句
   if len(name)<=0 then       'len函數獲得字串的長度
    response.write("<script>alert('郵件格式錯誤!')</script>") '字串長度小於等於0,則給出提示
    exit for       '跳出for迴圈
   end if
  next
 end if
%>
</body>
</html>


看個應用執行個體

if upload.form("uptype")="up" then ''如果是上傳圖片
i=1 '我覺得你放在下面i就不能遞加了 i始終都是1 
  for each formname in upload.file '列出所有上傳了的檔案 你確信upload.file是數組嗎?不是數組肯定報錯的
    set file=upload.file(formname)
 if trim(file.filename)<>"" then
 filetype=upload.form(formname)
    upload.savetofile formname,server.mappath(formpath&file.filename)
   
    url="url"'"&i&'"
 rs(url)=file.filename
 i=i+1
 end if'你缺少這個end if
  next '(這個就是48行)這個你沒注釋掉...
else
rs("url1")=uoload.form("url1")
rs("url2")=uoload.form("url2")
rs("url3")=uoload.form("url3")
end if
'代碼不全我就看出這麼多 你試試吧

asp for each in next迴圈語句
 asp指令碼迴圈語句for each...in...next

  迴圈語句的作用就是重複執行程式代碼,for...next 語句用於將語句塊運行指定的次數,在迴圈中使用計數器變數,該變數的值隨每一次迴圈增加或減少。for each...in...next 不是將語句運行指定的次數,而是對於數組中的每個元素或對象集合中的每一項重複一組語句。這在不知道集合中元素的數目時非常有用。它的文法如下:


for each element in group
[statements]
[exit for]
[statements]
next [element]

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.