StringSet Usage Example

StringSet establishes a set of up to 26 strings. Each string is referenced by a letter of the alphabet. You can use StringSet's Expand function to replace every StringSet reference within a string with its assigned string. In a string processed by Expand, a given string is referenced by a special character (one not normally occuring in your strings) followed by its assigned letter. Here is an example of how you might use StringSet.

This piece of code is acting as a simple Mail Merge funtion. A file (Message.txt) containing a simple eMail message is being read, and processed once, for each person who is to receive the message. The message contains insertion points (StringSet references) for the eMail address, name, and phone number of the recipient. These insertion points are indicated, in the prototype message, as $A, $N, and $P.

Type ReplType as   'define UDT to hold recipient data
  eMail as String
  Name as String
  Phone as String
End Type
Dim Repl as ReplType

Dim ss as StringSet   'declare our StringSet
  FileName = "Message.txt"
  Lngth = FileLen(FileName)   'get length of file
  Strg = Space(Lngth)   'set up recepticle to hold file content
  FileNum = FreeFile   'get an available file number

  Set ss = New StringSet   'create the object
  ss.ShortCut = "$"   'set StringSet reference character to $
  Repl = NextAddressee   'get first addressee information

  While Repl.eMail <> ""   'loop through all addressees
    Call ss.PutString("A", Repl.eMail)   'set up eMail address substitutions, $A
    Call ss.PutString("N", Repl.Name)   'set up name substitutions, $N
    Call ss.PutString("P", Repl.Phone)   'set up phone number substitutions, $P
    Open FileName For Binary As FileNum   'open the file
    Get #FileNum, , Strg   'read entire file into Strg
    Close #FileNum   'close the file
    Msg = ss.Expand(Strg)   'perform the substitutions
    Call SendMessage(Msg)   'send out the eMail message
    Repl = NextAddressee   'get next addressee information
  Wend
End Sub