'MacroName:formHeadings
'MacroDescription:

global CS As Object   
'------------
function GetAllCorps
   dim temp$, x%
   
   x% = 1
   do
      CS.GetField "610", x%, corps$
      if corps$ > "" then
         if instr(corps$, "2 fast") or instr(corps$, "2 rbgenr") then
            ' do nothing
         else
            temp$ = temp$ & corps$ & "|"         
         end if
      else
         exit do
      end if
      x% = x% + 1
   loop

   GetAllCorps = temp$

end function
'------------
function GetAllGenres
   dim temp$, x%
   
   x% = 1
   do
      CS.GetField "655", x%, genre$
      if genre$ > "" then
         if instr(genre$, "2 fast") or instr(genre$, "2 rbgenr") then
            ' do nothing
         else
            temp$ = temp$ & genre$ & "|"         
         end if
      else
         exit do
      end if
      x% = x% + 1
   loop

   GetAllGenres = temp$

end function
'------------
function GetAllSubjects
   dim temp$, x%
   
   x% = 1
   do
      CS.GetField "650", x%, subject$
      if subject$ > "" then
         if instr(subject$, "2 fast") then
            'do nothing
         else
            temp$ = temp$ & subject$ & "|"         
         end if
      else
         exit do
      end if
      x% = x% + 1
   loop

   x% = 1
   do
      CS.GetField "651", x%, subject$
      if subject$ > "" then
         if instr(subject$, "2 fast") then
            'do nothing
         else
            temp$ = temp$ & subject$ & "|"         
         end if
      else
         exit do
      end if
      x% = x% + 1
   loop

   GetAllSubjects = temp$

end function
'------------
Sub Main

   Set CS = CreateObject("Connex.Client")
   AllGenres$ = GetAllGenres
   AllSubjects$ = GetAllSubjects      
   CS.GetFixedField "type", MARCtype$
   
   'biographies
   if Marctype$ = "i" then
      CS.GetFixedField "LTxt", biog$
   else      
      CS.GetFixedField "biog", biog$
   end if
   
   select case biog$
      case "a"
         form$ = "Autobiographies"
      case "b", "d"
         form$ = "Biographies"
   end select
   
   if instr(AllGenres$, form$) or form$ = "" then
      'do nothing
   else
      CS.AddField 99, "655 7" & form$
   end if
   
   'magazines
   CS.GetFixedField "SrTp", srtp$
   select case srtp$
      case "p"
         form$ = "Periodicals"
      case "n"
         form$ = "Newspapers"
      case else
         form$ = ""
   end select
   
   if instr(AllGenres$, form$) or form$ = "" then
      'do nothing
   else
      CS.AddField 99, "655 7" & form$
   end if

   'LitF
   CS.GetFixedField "LitF", LitF$
   select case LitF$
      case "d"
      case "e"
         temp$ = "Essays"
      case "f"
      case "h"
      case "i"
         temp$ = "Personal correspondence"
      case "j"
      case "p"
      case "s"
         temp$ = "Speeches"
      case else
         temp$ = ""         
   end select
   if temp$ > "" then CS.Addfield 99, "655 7" & temp$

   'anecdotes
   if instr(AllSubjects$, "v Anecdotes") then
      if instr(AllGenres$, "Anecdotes") then
         'do nothing
      else
         CS.Addfield 99, "655 7Anecdotes"
      end if      
   end if

   'conversation and phrase books
   if instr(AllSubjects$, "v Conversation and phrase books") then
      if instr(AllGenres$, "Phrase books") then
         'do nothing
      else
         CS.Addfield 99, "655 7Phrase books"
      end if      
   end if

   'correspondence
   if instr(AllSubjects$, "correspondence") then
      if instr(AllGenres$, "correspondence") then
         'do nothing
      else
         CS.Addfield 99, "655 7Personal correspondence"
      end if      
   end if

   'dictionaries
   if instr(AllSubjects$, "v Dictionaries") then
      if instr(AllGenres$, "Dictionaries") then
         'do nothing
      else
         CS.Addfield 99, "655 7Dictionaries"
      end if      
   end if

   'guidebooks
   if instr(AllGenres$, "Guidebooks") then
      'do nothing
   else
      if instr(AllSubjects$, "Guidebooks") then CS.AddField 99, "655 7Guidebooks"         
   end if

   'handbooks
   if instr(AllSubjects$, "v Handbooks, manuals") then
      if instr(AllGenres$, "Handbooks and manuals") then
         'do nothing
      else
         CS.Addfield 99, "655 7Handbooks and manuals"
      end if      
   end if
      
   'personal narratives
   if instr(AllSubjects$, "v Personal narratives") then
      if instr(AllGenres$, "Personal narratives") then
         'do nothing
      else
         CS.Addfield 99, "655 7Personal narratives"
      end if      
   end if
   
   'pictorial works
   if instr(AllSubjects$, "v Pictorial works") then
      if instr(AllGenres$, "Pictorial works") then
         'do nothing
      else
         CS.Addfield 99, "655 7Illustrated works"
      end if      
   end if

   'readers
   if instr(AllSubjects$, "v Readers") then
      if instr(AllGenres$, "Readers (Publications)") then
         'do nothing
      else
         CS.Addfield 99, "655 7Readers (Publications)"
      end if      
   end if
   
   'study guides
   if instr(AllSubjects$, "v Study guides") then
      if instr(AllGenres$, "Study guides") then
         'do nothing
      else
         CS.Addfield 99, "655 7Study guides"
      end if      
   end if

   'textbooks
   if instr(AllSubjects$, "v Textbooks") then
      if instr(AllGenres$, "Textbooks") then
         'do nothing
      else
         CS.Addfield 99, "655 7Textbooks"
      end if      
   end if

   'yearbooks
   AllCorps$ = GetAllCorps()
   if instr(AllCorps$, "Students " & chr(223) & "v Yearbooks") then
      if instr(AllGenres$, "yearbooks") then
         'do nothing
      else
         CS.Addfield 99, "655 7School yearbooks"
      end if      
   end if

End Sub