LOTUSSCRIPT LANGUAGE


Examples: Type statement
Example 1

' Define a type with members to hold name, area code,
' and 7-digit local phone number.
Type phoneRec
  name As String
  areaCode As Integer
  phone As String * 8
End Type

Dim x As phoneRec            ' x is a variable of type phoneRec.
x.name$ = "Rory"             ' Assign values to x's members.
x.areaCode% = 999
x.phone$ = "555-9320"

Print "Call " & x.name$ & " at " & Str$(x.areaCode%) & "-" & _   x.phone% Output:
' Call Rory at 999-555-9320"

Example 2

' Create an array to hold five instances of phoneRec.
Dim multiX(5) As phoneRec
multiX(2).name$ = "Maria"       ' Assign values.
multiX(2).areaCode% = 212
multiX(2).phone$ = "693-5500"

' Retrieve data from a type member.
Dim phoneLocalHold As String * 8
phoneLocalHold$ = multiX(2).phone$
Print phoneLocalHold$
' Output:
' 693-5500

Example 3

' To maintain a file that contains a phone list,
' read all of the data from the file into LotusScript.
' The data fills a list in which each element
' is an instance of the defined type.

' Create a list to hold records from the file.
Dim phoneList List As phoneRec

' Declare a phoneRec variable to hold
' each record from the file in turn. Open the file.
Dim tempRec As phoneRec
Open "c:\phones.txt" For Random Access Read Write _
  As #1 Len = Len(tempRec)

' Read the file and store the records in the list.
Dim recNum As Integer
recNum% = 1
While EOF(1) = FALSE
  Get #1, recNum%, tempRec
  phoneList(tempRec.Name$) = tempRec
  recNum% = recNum% + 1
Wend
Close #1
' Note that the Get statement automatically fills each
' member of the tempRec variable. Since tempRec and the
' elements of phoneList are both of data type phoneRec,
' tempRec can be assigned to any element of phoneList
' without reference to its members, which LotusScript
' copies automatically.

See Also