[asp.net]asp For Each语句实例

更新时间:2016-10-09    来源:圣诞节电子贺卡    手机版     字体:

【www.bbyears.com--圣诞节电子贺卡】

 


for each语句实例example27



 

请输入电子邮箱:>


 



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


看个应用实例

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]

本文来源:http://www.bbyears.com/ps/27407.html

猜你感兴趣