检查经典asp数组中的变量

tes*_*123 1 arrays variables asp-classic

我正在尝试检查变量的值是否在数组中.有一些困难.我的数组存储在global.asa中.

    Dim aTree(5)
   aTree(0) = "a"
    aTree(1) = "b"
    aTree(2) = "c"
    aTree(3) = "d"
    aTree(4) = "e"
    aTree(5) = "f"
       Application("aTree") = aTree 
Run Code Online (Sandbox Code Playgroud)

我试图检查的变量存储了一些html内容

<% If tree = "a" Then %>
     <div class="card bg_white">
            <h1 class="bold small-caps tbrown">my content</h1>
    </div>
<% End If %>
Run Code Online (Sandbox Code Playgroud)

我正试图以这种方式进行检查

<% tree = Request("tree") 
if in_array(tree, aTree) then %>
You've found it
<% End if %>
Run Code Online (Sandbox Code Playgroud)

我有这个笨重的版本

(tree <> "" and tree <> "a" and tree <> "b" and tree <> "c" and tree <> "d" and tree <> "e" and tree <> "f")
Run Code Online (Sandbox Code Playgroud)

但是我希望用数组做一个更优雅的方式.

没什么帮助.谢谢.

Mar*_*tha 7

没有内置InArray()函数,但它应该足够简单来构建自己的函数.

Function InArray(theArray,theValue)
    dim i, fnd
    fnd = False
    For i = 0 to UBound(theArray)
        If theArray(i) = theValue Then
            fnd = True
            Exit For
        End If
    Next
    InArray = fnd
End Function
Run Code Online (Sandbox Code Playgroud)

修改此函数以返回值的索引而不仅仅是true/false,这是读者的练习.:)