LotusScript でリストを処理する

LotusScript® では、リストで使用できる関数やステートメントを多数用意しています。

TypeName( listName ) は、dataType LIST 形式の文字列 (STRING LIST など) を返します。dataType は、リストを宣言するステートメント内に指定されたデータ型、またはステートメント内で暗黙のデータ型です。

TypeName( listName( listTag )) は、dataType 形式の文字列 (STRING など) を返します。dataType は、指定されたリスト要素のデータ型です。Variant 型には種々のデータ型を入れられるので、リストの型を Variant 型として宣言するときは、リスト内の個々の要素のデータ型を調べておくことをお勧めします。

DataType( listName ) は、2048 + dataTypeCode に等しい整数を返します。例えば、2056 が返されます (2048 + 8 で、LIST 型のコード + String 型のコード)。

DataType( listName( listTag )) は、指定された要素のデータ型コードを表す整数を返します。例えば 8 が返されます (String 型のコード)。

IsList( listName ) は、listName がリストかどうかにより、True (-1) または False (0) を返します。

IsElement( listName ( stringExpr )) は、stringExprlistName 内のリストタグかどうかにより、True (-1) または False (0) を返します。リスト内に特定のリストタグがあるかどうかを調べたほうが良い状況は、いろいろあります。その中の 2 つを次に示します。

ListTag( refVar ) は、ForAll ループで現在処理中の要素のリストタグを返します。refVar 引数は ForAll ループ内の参照変数です。

LotusScript は、container により識別されるリスト内の各要素に対して、ForAll refVar In container ブロック内のステートメントを実行します。

Erase listName は、listName 内のすべての要素を削除し、削除された要素に割り当てられていた記憶域を再要求します。Erase listName( listTag ) は、listTag により識別される個別の要素をリストから削除し、その要素に割り当てられていた記憶域を再要求し、リストの残りはそのまま残します。

これらの関数を次の例に示します。次の例では、ユーザーが有効な従業員名 (有効なリストタグ) と従業員 ID を入力すると、その従業員の駐車スペースへのアクセスを削除します。

' Declare a list to hold employee IDs.
' The list tags will be the names of the employees.
Dim empList List As Double
' Make absolutely sure empList is Double.
If TypeName(empList) <> "DOUBLE LIST" Then
  Print "Warning: empList is " & TypeName(empList)
End If
If DataType(empList) <> 2053 Then
  Print "Warning: empList is " & CStr(DataType(empList))
  ' We expected 2053 (that is, 2048 + 5).
End If
' Declare a String variable for user name.
Dim ans As String
' Declare a Double variable for user ID.
Dim yourID As Double
' Declare an Integer variable to serve as a flag.
Dim found As Boolean
' Create some list elements and assign them values.
empList("Maria Jones") = 12345
empList("Roman Minsky") = 23456
empList("Joe Smith") = 34567
empList("Sal Piccio") = 91234
' Ask the user to enter the name to be removed from the
' list of employees who have been assigned parking spaces.
ans$ = InputBox$("Which employee no longer needs a space?")
' Check to see if the employee's name appears as a list tag
' in the list. If not, display a message and stop. Otherwise,
' validate the employee's ID. If everything checks out,
' remove the employee item from the parking list. 
If IsElement(empList(ans$)) = True then
    Print ans$ & "  is a valid employee name."
    yourID# = CDbl(InputBox$("What's " & ans$ & "'s ID?"))
    ' The following ForAll block does two things:
    ' it checks to see if yourID# is a valid ID and,
    ' if so, if it matches the ID for the employee
    ' whose name is ans$. If so, that element is removed
    ' (erased) from the list. The found flag is initially
    ' FALSE (0). If yourID# is a valid ID, found is set to
    ' TRUE (-1). The variable empID is the reference variable
    ' in the ForAll loop.
    found = FALSE
    ForAll empID In empList
        If empID = yourID# then
           found = TRUE
           If ListTag(empID) = ans$ then
              Erase empList(ans$)
              ' Verify the removal of the list element.
              If  IsElement(empList(ans$)) = FALSE then
                Print ans$ & " is no longer on the list."
             End If
           Else
              Print "Valid ID but wrong employee."
           End If
           ' No need to look further for yourID#,
           ' so get out of the ForAll loop.
           Exit ForAll
        End If
     End ForAll
     If found = False then
        Print "No such employee ID."
     End If
Else
   Print "No such employee."
End if