'MacroName:fictionGenres

option base 1

'--------------------   
function replace(strString as string, strOld as string, strNew as string) as string
   dim pos as integer
   pos = instr(strString, strOld)
   do while pos > 0
      strString = left(strString, pos - 1) & strNew & mid(strString, pos + len(strOld))
      pos = instr(strString, strOld)
   loop
   replace = strString   
end function
'-------------------
function convert655(genre$) as string
   dim temp$
   
   temp$ = mid(genre$, 6)
   pos% = instr(temp$, chr(223))
   if pos% > 0 then temp$ = left(temp$, pos% - 2)
   
   temp$ = replace(temp$, "Mystery fiction", "Detective and mystery fiction")
   temp$ = replace(temp$, "Legal stories", "Legal fiction (Literature)")
   'temp$ = replace(temp$, "Satire", "Satires (Literature)")
   temp$ = replace(temp$, "Love stories", "Romance fiction")
   temp$ = replace(temp$, " stories", " fiction")
   temp$ = replace(temp$, "comic books, strips, etc.", "comics.")   
   
   convert655 = temp$
end function
'-------------------
Sub Main

   Dim CS As Object
   Set CS = CreateObject("Connex.Client")

   dim genres(15)
   
   x% = 1
   do
      CS.GetField "655", x%, temp$
      if instr(temp$, "gsafd") then
         temp$ = convert655(temp$)
         count% = count% + 1
         genres(count%) = temp$
      end if    
      x% = x% + 1
   loop until temp$ = ""
      
   if count% > 0 then
      for y% = 1 to count%
         CS.AddField count% + 30, "655 0" & genres(y%)
      next
   end if

   CS.Reformat   
   CS.CursorRow = 999
End Sub