如何优化这段代码,在线等待

teddyboy98 2003-11-16 02:28:37
if instr(path,("总经理"))>0 then
response.write("<input type='button' name='Button2'value='上传文件' class='bt1' style='width:60;height:19' onclick='upload();'>")
else
……'中间部份略去
if instr(path,("path/财务部"))>0 then
response.write("<input type='button' name='Button2'value='上传文件' class='bt1' style='width:60;height:19' onclick='upload();'>")
else
……'中间部份略去
if instr(path,("path/总经理"))>0 then
response.write("<input type='button' name='Button2'value='上传文件' class='bt1' style='width:60;height:19' onclick='upload();'>")
else
……
if instr(path,("path/财务部"))>0 then
response.write("<input type='button' name='Button2'value='上传文件' class='bt1' style='width:60;height:19' onclick='upload();'>")
else
response.Write("<input type='button' name='Button2' value='无权上传' class='bt1' style='width:60;height:19'>")
end if
注:
if instr(path,("总经理"))>0 then
if instr(path,("path/总经理"))>0 then
不同在于path,请高手救命!

...全文
50 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
chen8967 2003-11-16
  • 打赏
  • 举报
回复
有个问题,需要请教:如果这个人的身份是多重身份,如何解决?
foxty 2003-11-16
  • 打赏
  • 举报
回复
instr(path,("总经理"))>0
这里就不能这样写,你应该给每个用户一个标识例如,uid

当是总经理登陆的时候就给这个uid 赋值=总经理

然后就这样判断

if instr(path,uid)>0 then
说明该用户所在路径正确。

else
就超出了权限。
end if

这样一个语句就可以,何必用那么多27个语句来判断,如果又添加了用户你还要再加语句。

明白我的意思不?
foxty 2003-11-16
  • 打赏
  • 举报
回复
tt
离子漂浮物 2003-11-16
  • 打赏
  • 举报
回复
aryList=array("path/行财总监","path/销售总监",.......,"path/财务部")内不内包含"总经理" and "path/总经理"
离子漂浮物 2003-11-16
  • 打赏
  • 举报
回复
dim aryList
dim aryIndex
dim blnQx
dim strQx

blnQx=false
strQx=""

aryList=array("path/行财总监","path/销售总监",.......,"path/财务部")

for each aryIndex in aryList
if instr(path,aryIndex)>0 then
blnQx=true
strQx=aryIndex
exit for
end if
next

if (not blnQx) and instr(path,("总经理"))>0 then
blnQx=true
strQx="总经理"
if instr(path,("path/总经理"))>0 then
strQx="path/总经理"
end if
end if

if blnQx then
response.write("<input type='button' name='Button2'value='上传文件 部门'" & strQx & " class='bt1' style='width:60;height:19' onclick='upload();'>")
else
response.Write("<input type='button' name='Button2' value='无权上传' class='bt1' style='width:60;height:19'>")
end if
超级大笨狼 2003-11-16
  • 打赏
  • 举报
回复
我给你一个最新的脚本帮助文件吧。
http://download.microsoft.com/download/winscript56/Install/5.6/W982KMe/CN/scd56chs.exe
Visual Basic Scripting Edition

Select Case 语句
请参阅
If...Then...Else 语句
要求
版本 1
根据表达式的值执行几组语句之一。

Select Case testexpression
[Case expressionlist-n
[statements-n]] . . .
[Case Else expressionlist-n
[elsestatements-n]]
End Select
参数
testexpression
任意数值或字符串表达式。
expressionlist-n
如 Case 出现则必选项。一个或多个表达式的分界列表。
statements-n
当 testexpression 与 expressionlist-n 中的任意部分匹配时,执行的一条或多条语句。
elsestatements-n
当 testexpression 与 Case 子句的任何部分不匹配时,执行的一条或多条语句。
说明
如果 testexpression 与任何 Case expressionlist 表达式匹配,则执行此 Case 子句和下一个 Case 子句之间的语句,对于最后的子句,则会执行该子句到 End Select 之间的语句,然后控制权会转到 End Select 之后的语句。如 testexpression 与多个 Case 子句中的 expressionlist 表达式匹配,则只有第一个匹配后的语句被执行。

Case Else 用于指示若在 testexpression 和任何其他 Case 选项的 expressionlist 之间未找到匹配,则执行 elsestatements。虽然不是必要的,但最好是将 Case Else 语句置于 Select Case 块中以处理不可预见的 testexpression 值。如果没有 Case expressionlist 与 testexpression 匹配且无 Case Else 语句,则继续执行 End Select 之后的语句。

Select Case 语句可以是嵌套的,每一层嵌套的 Select Case 语句必须有与之匹配的 End Select 语句。

下面例子举例说明如何使用 Select Case 语句:

Dim Color, MyVar
Sub ChangeBackground (Color)
MyVar = lcase (Color)
Select Case MyVar
Case "red" document.bgColor = "red"
Case "green" document.bgColor = "green"
Case "blue" document.bgColor = "blue"
Case Else MsgBox "选择另一种颜色"
End Select
End Sub
要求
版本 1

请参阅
If...Then...Else 语句



--------------------------------------------------------------------------------

© 2001 Microsoft Corporation. 保留所有权利。

teddyboy98 2003-11-16
  • 打赏
  • 举报
回复
if instr(path,("总经理"))>0 then
response.write("<input type='button' name='Button2'value='上传文件' class='bt1' style='width:60;height:19' onclick='upload();'>")
else
response.write("")
end if
%>
<%
if instr(path,("path/行财总监"))>0 then
response.write("<input type='button' name='Button2'value='上传文件' class='bt1' style='width:60;height:19' onclick='upload();'>")
else
response.write("")
end if
%>
<%
if instr(path,("path/销售总监"))>0 then
response.write("<input type='button' name='Button2'value='上传文件' class='bt1' style='width:60;height:19' onclick='upload();'>")
else
response.write("")
end if
%>
<%
if instr(path,("path/营运总监"))>0 then
response.write("<input type='button' name='Button2'value='上传文件' class='bt1' style='width:60;height:19' onclick='upload();'>")
else
response.write("")
end if
%>
<%
if instr(path,("path/厂长"))>0 then
response.write("<input type='button' name='Button2'value='上传文件' class='bt1' style='width:60;height:19' onclick='upload();'>")
else
response.write("")
end if
%>
<%
if instr(path,("path/MIS部经理"))>0 then
response.write("<input type='button' name='Button2'value='上传文件' class='bt1' style='width:60;height:19' onclick='upload();'>")
else
response.write("")
end if
%>
<%
if instr(path,("path/销售部经理"))>0 then
response.write("<input type='button' name='Button2'value='上传文件' class='bt1' style='width:60;height:19' onclick='upload();'>")
else
response.write("")
end if
%>
<%
if instr(path,("path/采购部经理"))>0 then
response.write("<input type='button' name='Button2'value='上传文件' class='bt1' style='width:60;height:19' onclick='upload();'>")
else
response.write("")
end if
%>
<%
if instr(path,("path/人事部经理"))>0 then
response.write("<input type='button' name='Button2'value='上传文件' class='bt1' style='width:60;height:19' onclick='upload();'>")
else
response.write("")
end if
%>
<%
if instr(path,("path/生产部经理"))>0 then
response.write("<input type='button' name='Button2'value='上传文件' class='bt1' style='width:60;height:19' onclick='upload();'>")
else
response.write("")
end if
%>
<%
if instr(path,("path/品管部经理"))>0 then
response.write("<input type='button' name='Button2'value='上传文件' class='bt1' style='width:60;height:19' onclick='upload();'>")
else
response.write("")
end if
%>
<%
if instr(path,("path/彩印部经理"))>0 then
response.write("<input type='button' name='Button2'value='上传文件' class='bt1' style='width:60;height:19' onclick='upload();'>")
else
response.write("")
end if
%>
<%
if instr(path,("path/工程部经理"))>0 then
response.write("<input type='button' name='Button2'value='上传文件' class='bt1' style='width:60;height:19' onclick='upload();'>")
else
response.write("")
end if
%>
<%
if instr(path,("path/财务部经理"))>0 then
response.write("<input type='button' name='Button2'value='上传文件' class='bt1' style='width:60;height:19' onclick='upload();'>")
else
response.write("")
end if
%>
<%
if instr(path,("path/PMC"))>0 then
response.write("<input type='button' name='Button2'value='上传文件' class='bt1' style='width:60;height:19' onclick='upload();'>")
else
response.write("")
end if
%>
<%
if instr(path,("path/mis部"))>0 then
response.write("<input type='button' name='Button2'value='上传文件' class='bt1' style='width:60;height:19' onclick='upload();'>")
else
response.write("")
end if
%>
<%
if instr(path,("path/彩印部"))>0 then
response.write("<input type='button' name='Button2'value='上传文件' class='bt1' style='width:60;height:19' onclick='upload();'>")
else
response.write("")
end if
%>
<%
if instr(path,("path/仓库部"))>0 then
response.write("<input type='button' name='Button2'value='上传文件' class='bt1' style='width:60;height:19' onclick='upload();'>")
else
response.write("")
end if
%>
<%
if instr(path,("path/生产部"))>0 then
response.write("<input type='button' name='Button2'value='上传文件' class='bt1' style='width:60;height:19' onclick='upload();'>")
else
response.write("")
end if
%>
<%
if instr(path,("path/厂长办公室"))>0 then
response.write("<input type='button' name='Button2'value='上传文件' class='bt1' style='width:60;height:19' onclick='upload();'>")
else
response.write("")
end if
%>
<%
if instr(path,("path/工程部"))>0 then
response.write("<input type='button' name='Button2'value='上传文件' class='bt1' style='width:60;height:19' onclick='upload();'>")
else
response.write("")
end if
%>
<%
if instr(path,("path/销售部"))>0 then
response.write("<input type='button' name='Button2'value='上传文件' class='bt1' style='width:60;height:19' onclick='upload();'>")
else
response.write("")
end if
%>
<%
if instr(path,("path/报关组"))>0 then
response.write("<input type='button' name='Button2'value='上传文件' class='bt1' style='width:60;height:19' onclick='upload();'>")
else
response.write("")
end if
%>
<%
if instr(path,("path/人事部"))>0 then
response.write("<input type='button' name='Button2'value='上传文件' class='bt1' style='width:60;height:19' onclick='upload();'>")
else
response.write("")
end if
%>
<%
if instr(path,("path/品管部"))>0 then
response.write("<input type='button' name='Button2'value='上传文件' class='bt1' style='width:60;height:19' onclick='upload();'>")
else
response.write("")
end if
%>
<%
if instr(path,("path/采购部"))>0 then
response.write("<input type='button' name='Button2'value='上传文件' class='bt1' style='width:60;height:19' onclick='upload();'>")
else
response.write("")
end if
%>
<%
if instr(path,("path/财务部"))>0 then
response.write("<input type='button' name='Button2'value='上传文件' class='bt1' style='width:60;height:19' onclick='upload();'>")
else
response.write("")
end if
%>
Stiven_PFan 2003-11-16
  • 打赏
  • 举报
回复
当然用select case啊,用if的话,程序怎么读啊。
teddyboy98 2003-11-16
  • 打赏
  • 举报
回复
if instr(path,("总经理"))>0 then
if instr(path,("path/总经理"))>0 then
这里“总经理”是部门,共有27个部门,这样如何做呢
longmingli 2003-11-16
  • 打赏
  • 举报
回复
select case
teddyboy98 2003-11-16
  • 打赏
  • 举报
回复
总共重复了27次,如何解呀
  • 打赏
  • 举报
回复
用select case试试

28,408

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧