2016-04-22 13 views
0

変数の値が配列内にあるかどうかを確認しようとしています。いくつかの困難を抱えている。私の配列はglobal.asaに保存されています。古典的なASP配列の変数を確認してください

Dim aTree(5) 
    aTree(0) = "a" 
    aTree(1) = "b" 
    aTree(2) = "c" 
    aTree(3) = "d" 
    aTree(4) = "e" 
    aTree(5) = "f" 
     Application("aTree") = aTree 

私はこの不格好なバージョンを持っている私は、チェックをこのよう

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

をやろうとしている店にいくつかのHTMLコンテンツ

<% If tree = "a" Then %> 
    <div class="card bg_white"> 
      <h1 class="bold small-caps tbrown">my content</h1> 
    </div> 
<% End If %> 

をチェックしようとしている変数その作品

(tree <> "" and tree <> "a" and tree <> "b" and tree <> "c" and tree <> "d" and tree <> "e" and tree <> "f") 

Bu私は配列でそれを行うよりエレガントな方法が欲しいです。

リトルヘルプ。ありがとう。

答えて

4

組み込みの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 

この関数を変更して、true/falseの代わりに値のインデックスを返すことは、読者の練習として残されています。 :)

関連する問題