asp编写函数的问题!

来源:百度知道 编辑:UC知道 时间:2024/06/25 03:16:19
1,为什么下面那个函数名后带有参数,有什么做用吗?
2,为什么这里要定义为真呀:CheckLetter = True
3,这个字符串的值从哪里取来?len(str)

<%
Function CheckLetter(str) CheckLetter = True Letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
for i=1 to len(str) checkchar = UCase(Mid(str,i,1))
If (InStr(Letters,checkchar)<=0) Then CheckLetter = False
Exit Function End If
Next End Function
%>

1.这个函数是判断输入字符串的每一个
字符是否为变量Letters中所指定的字符,所以必须要有输入变量str
2.因为这个函数是判断输入的字符串的每一个字符是否为变量Letters中所指定的字符,如果有一个字符不是的话,那就跳出循环For,则返回False,如果通过则变量不变(True)
3.这只是一个函数,需要有程序调用的,例如
<%
a="1A"
result=CheckLetter(a)
if result=False then
response.write "Error!"
else
resposne.write "OK!"
end if
Function CheckLetter(str)
CheckLetter = True
Letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
for i=1 to len(str)
checkchar = UCase(Mid(str,i,1))
If (InStr(Letters,checkchar)<=0) Then
CheckLetter = False
Exit Function
End If
Next
End Function
%>
运行结果为:Error!
因为变量a中有Letters种没有的字符
以此来调用此函数的