' MacroName: Export-by-Paste ' MacroDescription: Exporting to LIBS+ workaround using macros, ' cut and paste ' Written by: Joel Hahn, Niles Public Library District Declare Function CheckMessage(Text$, Beginning$, Ending$) Declare Function CheckLine(Tag$) Declare Function LCCN(lc$) As String Declare Sub FixedFields(a$, b$) Declare Sub MainHandler(a$, b$) Declare Sub DoubleO(a$, b$) Declare Sub FiveOhFive(a$, b$) Declare Sub NineTen(a$, b$) Dim CCSSession as Session '*************************************************** function CheckMessage(Text$, Beginning$, Ending$) bRetVal = FALSE Temp$ = Left$(Text$, Len(Beginning$)) if StrComp(Beginning$, Temp$) = 0 then Temp$ = Right$(Text$, Len(Ending$)) if StrComp(Ending$, Temp$) = 0 then bRetVal = TRUE end if end if CheckMessage = bRetVal end function '*************************************************** function CheckLine(Tag$) tRetVal=FALSE Dim CCST as Session Dim CCSTest as Session CurrentSession.GetName CurSession$ NumSessions%=GetNumSessions() For i=1 to NumSessions% Set CCST=GetSession(i) CCST.GetName SessionName$ If (SessionName$="Telnet to CCS") Then Set CCSTest=CCST End if Next i Digits%=Len(Tag$) Crow%=(CCSTest.CursorRow) CCSTest.GetTextInRegion CheckTag$,Crow%,17,Crow%,(16+Digits%) 'If Tag$="999" Then MsgBox CheckTag$ & "|" & Tag$ If CheckTag$=Tag$ Then tRetVal=TRUE CheckLine=tRetVal end function '*************************************************** sub main Dim CS as Session Set CS = CurrentSession Dim CCS as Session 'Set up Session names 'CurSession [also CS] is OCLC; find the next open non-OCLC 'session and make it CCSSession. Commands may then be sent 'to either session by choosing the proper preface. CurrentSession.GetName CurSession$ NumSessions%=GetNumSessions() For i=1 to NumSessions% Set CCS=GetSession(i) CCS.GetName SessionName$ If (SessionName$<>CurSession$) Then Set CCSSession=CCS End if Next i CCSSession.GetTextInRegion MarcTest$, 3, 32, 3, 37 If Left(Trim(MarcTest$), 4)<>"MARC" Then MsgBox "CLSI display is not in a MARC record. Aborting..." Goto Done End If 'If the cursor is not currently in the Tag column of the 'MARC display, move it there cc=CCSSession.CursorColumn If cc=21 or cc=22 Then CCSSession.Send "\x09\x09\x09" CCSSession.Receive 5, "[?25l" ElseIf cc=25 Then CCSSession.Send "\x09\x09" CCSSession.Receive 5, "[?25l" ElseIf cc>=27 Then CCSSession.Send "\x09" CCSSession.Receive 5, "[?25l" End If 'Make sure cursor is at the first available line of the MARC 'display, moving it there if necessary ccr=CCSSession.CursorRow CCSSession.GetTextInRegion LinNums$, 3, 1, 3, 80 LNplace=Instr(LinNums$, "Line") LinNums$=Right(LinNums$, Len(LinNums$)-LNplace) LNplace2=Instr(LinNums$, "of") CurLin=Val(Mid(LinNums$, 4, LNplace2-4)) If CurLin<>3 Then UpLine=CurLin Do CCSSession.Send "\x1B[A" CCSSession.Receive 5, "[?25l" UpLine=UpLine-1 Loop while UpLine>3 CCSSession.Send "\x1B[17~" '[F6] End If ' Determine how many columns are in the OCLC record if CS.CommMode = BLOCK then Columns% = CS.BlockColumns else Columns% = CS.FDXColumns end if ' Make sure we are at the top of the record CS.GetTextInRegion Text$, 2, 1, 2, Columns% ' Check for "Entire --- displayed." if CheckMessage(Text$, "Entire ", " displayed.") = FALSE then ' Check for "Beginning of --- displayed." if CheckMessage(Text$, "Beginning of ", " displayed.") = FALSE then ' Check for "You are already at beginning of the ---" if CheckMessage(Text$, "You are already at beginning of the ", "") = FALSE then ' Check for "You are already viewing the entire ---" if CheckMessage(Text$, "You are already viewing the entire ", "") = FALSE then ' Move position to the beginning of the record CS.PutText "HOME", 1, 1 RunMacro "PRSMUTIL!SendCommand" end if end if end if end if bLoop% = TRUE nPages = 0 ' Get text to be printed Do While bLoop% = TRUE Row% = CS.GetLastRowUsed CS.GetTextInRegion Temp$, 6, 1, Row%, Columns%, TRUE Buffer$ = Buffer$ + Temp$ ' Get message at the top of the record CS.GetTextInRegion Text$, 2, 1, 2, Columns% bLoop% = FALSE bAtTop% = FALSE ' Check for "Entire --- displayed." if CheckMessage(Text$, "Entire ", " displayed.") = TRUE then bAtTop% = TRUE else ' Check for "End of --- displayed." if CheckMessage(Text$, "End of ", " displayed.") = FALSE then ' Check for "You are already at end of the ---" if CheckMessage(Text$, "You are already at end of the ", "") = FALSE then ' Check for "You are already viewing the entire ---" if CheckMessage(Text$, "You are already viewing the entire ", "") = TRUE then bAtTop% = TRUE else ' Move to the next page RunMacro "PRSMUTIL!PageDown" nPages = nPages + 1 ' Allow only 15 pages to print if nPages < 15 then bLoop% = TRUE end if end if end if end if end if Loop ' Move position to the beginning of the record if bAtTop% = FALSE then CS.PutText "HOME", 1, 1 RunMacro "PRSMUTIL!SendCommand" end if wraps=0 For g=1 to LEN(Buffer$) If mid(Buffer$, g, 1)=CHR$(13) then wraps=wraps+1 Next g crlf=CHR$(13)+CHR$(10) for g=1 to wraps place=InStr(Buffer$, crlf) l$=Left(Buffer$, place-1) r$=Right(Buffer$, (Len(Buffer$)-(place+1))) '*** Buffer$=l$+r$ next g '*************************************************** FixedFields: '001, 003, 008 dim a$ dim b$ Call FixedFields(a$, b$) '*************************************************** Body: '!!! must make check for all additional lines (949, 965, 999, etc.) !!! 'On Error Goto Done2 Do While CheckLine("9")=FALSE CCSSession.Send "\x1B[2~" CCSSession.Receive 50, "[?25l" '" " '...Receive 5,... Loop Do While CheckLine("9")=TRUE CCSSession.Send "\x1B[2~" CCSSession.Receive 50, "[?25l" '" " '...Receive 5,... Loop 'Do While (CheckLine("910")=FALSE) '999 ' If (CheckLine("777")=TRUE) Then Exit Do ' CCSSession.Send "\x1B[2~" ' CCSSession.Receive 20, " " '...Receive 2,... 'Loop 'If (CheckLine("999")=TRUE) Then CCSSession.Send "\x1B[2~" Lines=0 For h=1 to LEN(Buffer$) if mid(Buffer$, h, 1)=CHR$(221) then Lines=Lines+1 Next h li=2 Do While li<=Lines CCSSession.Send "\r" b$=GetField(Buffer$, li, CHR$(221)) GetLine: dim c$ dim d$ dim delim as String delim=CHR$(223) subf=0 '# of subfields subc=0 'subfield progress counter de=0 '0=1st subfield is $a; 1=1st subfield is not $a 'Get tag & indicators; jump to special line handler for 'lines not handled in the standard way If Mid(b$, 8, 2)="00" Then Call DoubleO(a$, b$) Goto Retn ElseIf Mid(b$, 7, 1)="[" Then Call FiveOhFive(a$, b$) Goto Retn ElseIf Mid(b$, 8, 3)="910" Then Call NineTen(a$, b$) Goto Retn Else a$=Mid(b$, 8, 3)+Mid(b$, 12, 2) End If '*************************************************** Call Mainhandler (a$, b$) '*************************************************** Retn: CCSSession.Send a$ li=li+1 Loop '*************************************************** 'Done2: ' If Err=102 Then Resume Next Done: end sub '*************************************************** Sub MainHandler(a$, b$) delim=Chr$(223) If Mid(b$, 16, 1)<>delim Then a$=a$+"a" de=0 Else de=1 End If SubfieldCount: For i=16 to Len(b$) If Mid(b$, i, 1)=delim Then subf=subf+1 If subf=0 Then subf=1 Next i If de=1 then subf=subf+1 SubfieldLoop: Dim subx as Integer Dim lenD as Integer subx=0 subc=1 Do c$=GetField(b$, subc, CHR$(223)) If (subc<>1) or (de=1) Then d$=Mid(c$, 3, Len(c$)-3) If subc<>1 Then a$=a$+Left(c$, 1) '***Does 015 get translated like 010 by MarcParms?? If Left(a$, 3)="010" Then d$=LCCN(d$) End If If Len(d$)>50 Then lenD=Len(d$) subx=lenD\50 'should be same as Int(.../50) If (lenD MOD 50)=0 Then subx=subx-1 End If End If Else If de=1 Then Goto Looper Else d$=RTrim(Mid(c$, 16, Len(c$)-16)) If Left(a$, 3)="010" Then d$=LCCN(d$) End If If Len(d$)>50 Then lenD=Len(d$) subx=lenD\50 'should be same as Int(.../50) If (lenD MOD 50)=0 Then subx=subx-1 End If End If End if End if a$=a$+d$ If subc<>subf Then a$=a$+"\r" Looper: subc=subc+1 Loop While subc<=subf If de=1 then subf=subf-1 For i=1 to (subf+subx) a$=a$+"\x1B[A" Next a$=a$+"\x09" End Sub '*************************************************** Sub DoubleO(a$, b$) DoubleO: b$=RTrim(b$) a$=Mid(b$, 8, 3) If Mid(b$, 8, 3)="006" Then c$=Right(Left(b$, Len(b$)-1), Len(b$)-17) a$=a$+c$ subf=1 Else SubfieldCount2: delim=Chr$(223) subf=1 For i=16 to Len(b$) If Mid(b$, i, 1)=delim Then subf=subf+1 Next i SubfieldLoop2: subc=1 del1=0 Do c$=GetField(b$, subc, CHR$(223)) If subc=1 Then del2=1 d$=Mid(c$, 16, 1) ' Len(c$)-16) Else del2=ASC(Mid(c$, 1, 1))-96 d$=Mid(c$, 3, 1) ' Len(c$)-3) End if If del2<>del1+1 Then If del2=4 Then a$=a$+"u" Else dash=del2-(del1+1) For k=1 to dash a$=a$+"-" Next k End If End If a$=a$+d$ del1=del2 subc=subc+1 Loop While subc<=subf End If : subf=1 End Sub '*************************************************** Function LCCN(lc$) dim ln$ If Mid(b$, 16, 1)<>delim Then a$=Mid(b$, 8, 3)+" a" 'Get Marc tag de=0 Else de=1 End If SubfieldCountLCCN: For i=16 to Len(b$) If Mid(b$, i, 1)=delim Then subf=subf+1 If subf=0 Then subf=1 Next i If de=1 then subf=subf+1 ' lc$=RTrim(Mid(b$, 16, Len(b$)-16)) ' asci=ASC(Left(lc$, 1)) ' If ASC(Left(lc$, 1))>97 and ASC(Left(lc$, 1))<123 Then ' a$=a$+Left(lc$, 2)+" " ' lc$=Right(lc$, Len(lc$)-2) ' Else ' a$=a$+" " ' End If ' a$=a$+Left(lc$, 2) ' ' lc$=Right(lc$, Len(lc$)-3) ' j=1 ' Do While j<=Len(lc$) ' check=ASC(Mid(lc$, j, 1)) ' If check<48 or check>57 Then ' ln$=LTrim(Mid(lc$, j, Len(lc$)-(j-1))) ' lc$=Left(lc$, j-1) ' Exit Do ' End If ' j=j+1 ' Loop ' ' If 6-Len(lc$)<>0 Then ' For i=1 to (6-Len(lc$)) ' lc$="0"+lc$ ' Next i ' End if ' subf=1 ' a$=a$+lc$+" "+ln$ SubfieldLoopLCCN: ' Dim subx as Integer ' Dim lenD as Integer subx=0 subc=1 Do lc$="" : ln$="" c$=GetField(b$, subc, CHR$(223)) If (subc<>1) or (de=1) Then d$=Mid(c$, 3, Len(c$)-3) If subc<>1 Then a$=a$+Mid(c$, 1, 1) If Len(d$)>50 Then lenD=Len(d$) subx=lenD\50 'should be same as Int(.../50) If (lenD MOD 50)=0 Then subx=subx-1 End If End If Else If de=1 Then Goto LooperLCCN Else d$=RTrim(Mid(c$, 16, Len(c$)-16)) If Len(d$)>50 Then lenD=Len(d$) subx=lenD\50 'should be same as Int(.../50) If (lenD MOD 50)=0 Then subx=subx-1 End If End If End if End if lc$=d$ 'RTrim(Mid(b$, 16, Len(b$)-16)) asci=ASC(Left(lc$, 1)) If ASC(Left(lc$, 1))>97 and ASC(Left(lc$, 1))<123 Then a$=a$+Left(lc$, 2)+" " lc$=Right(lc$, Len(lc$)-2) Else a$=a$+" " End If a$=a$+Left(lc$, 2) lc$=Right(lc$, Len(lc$)-3) j=1 Do While j<=Len(lc$) check=ASC(Mid(lc$, j, 1)) If check<48 or check>57 Then ln$=LTrim(Mid(lc$, j, Len(lc$)-(j-1))) lc$=Left(lc$, j-1) Exit Do End If j=j+1 Loop If 6-Len(lc$)<>0 Then For i=1 to (6-Len(lc$)) lc$="0"+lc$ Next i End if 'subf=1 a$=a$+lc$+" "+ln$ If subc<>subf Then a$=a$+"\r" LooperLCCN: subc=subc+1 Loop While subc<=subf LCCN=lcn$ End Function '*************************************************** Sub FiveOhFive(a$, b$) FiveOhFive: 'Used only for "[1] 505", "[2] 505", etc. If Mid(b$, 20, 1)<>delim Then a$=Mid(b$, 12, 3)+Mid(b$, 16, 2)+"a" c$=Mid(b$, 20, Len(b$)-20) If Len(c$)>50 Then lenC=Len(c$) subx=lenC\50 If (lenC MOD 50)=0 Then subx=subx-1 End If End If a$=a$+c$ subf=1 de=0 Else SubfieldCount505: For i=19 to Len(b$) If Mid(b$, i, 1)=delim Then subf=subf+1 If subf=0 Then subf=1 Next i subf=subf+1 SubfieldLoop505: 'Dim subx as Integer 'Dim lenD as Integer subx=0 subc=1 Do c$=GetField(b$, subc, CHR$(223)) If subc<>1 Then d$=Mid(c$, 3, Len(c$)-3) a$=a$+Mid(c$, 1, 1) If Len(d$)>50 Then lenD=Len(d$) subx=lenD \ 50 'should be same as Int(.../50) If (lenD MOD 50)=0 Then subx=subx-1 End If End If Else Goto Looper505 End if a$=a$+d$ If subc<>subf Then a$=a$+"\r" Looper505: subc=subc+1 Loop While subc"001" Then OneX=1 If (One$<>"003") and (Three$<>"003") Then ThreeX=1 'Goto Done a$="001ocm" place=0 place=InStr(b$, "OCLC") o$=RTrim(Mid(b$, place+7, 8)) If 8-Len(o$)<>0 Then For i=1 to (8-Len(o$)) o$="0"+o$ Next i End if a$=a$+o$ If OneX=0 Then CCSFF.Send "\x1B[2~" End If If ThreeX=0 Then CCSFF.Send "\x1B[2~" End If ' CCSFF.Send "\x1B[B" ' Do While (CheckLine("00")=TRUE) ' CCSFF.Send "\x1B[2~" ' Loop ' CCSFF.Send "\x1B[A" CCSFF.Send "\r" CCSFF.Send a$ CCSFF.Send "\r" CCSFF.Send "003OCoLC" CCSFF.Send "\r" 'Start Header info; get info for first 18 positions a$="008" place=InStr(b$, "Entered") a$=a$+Mid(b$, place+14, 6) place=InStr(b$, "DtSt") a$=a$+Mid(b$, place+7, 1) place=InStr(b$, "Dates") a$=a$+Mid(b$, place+7, 4)+Mid(b$, place+12, 4) place=InStr(b$, "Ctry") a$=a$+Mid(b$, place+7, 3) 'Get Type, goto Fixed Fields set for the appropriate format place=InStr(b$, "Type") typ=ASC(Mid(b$, place+7, 1)) Select Case typ Case 97 'Type="a" If InStr(b$, "SrTp")=0 then Goto Bks Else Goto Ser Case 99 'Type="c" Goto Sco Case 101 'Type="e" Goto Map Case 103, 107, 111 'Type="g", "k", or "o" Goto Vis Case 105, 106 'Type="i" or "j" Goto Rec Case 109 'Type="m" Goto Com End Select Bks: place=InStr(b$, "Ills") a$=a$+Mid(b$, place+7, 4) place=InStr(b$, "Audn") 'aka Int Lvl a$=a$+Mid(b$, place+7, 1) place=InStr(b$, "Form") 'aka Repr a$=a$+Mid(b$, place+7, 1) place=InStr(b$, "Cont") a$=a$+Mid(b$, place+7, 4) place=InStr(b$, "GPub") a$=a$+Mid(b$, place+7, 1) place=InStr(b$, "Conf") a$=a$+Mid(b$, place+7, 1) place=InStr(b$, "Fest") a$=a$+Mid(b$, place+7, 1) place=InStr(b$, "Indx") a$=a$+Mid(b$, place+7, 1) a$=a$+" " 'aka MEBE place=InStr(b$, "LitF") 'aka Fict a$=a$+Mid(b$, place+7, 1) place=InStr(b$, "Biog") a$=a$+Mid(b$, place+7, 1) Goto End008 Ser: place=InStr(b$, "Freq") a$=a$+Mid(b$, place+7, 1) place=InStr(b$, "Regl") a$=a$+Mid(b$, place+7, 1) place=InStr(b$, "ISSN") 'aka ISDS a$=a$+Mid(b$, place+7, 1) place=InStr(b$, "SrTp") a$=a$+Mid(b$, place+7, 1) place=InStr(b$, "Orig") 'aka Phys.Med. a$=a$+Mid(b$, place+7, 1) place=InStr(b$, "Form") 'aka Repr a$=a$+Mid(b$, place+7, 1) place=InStr(b$, "EntW") 'aka 1st character of Cont a$=a$+Mid(b$, place+7, 1) place=InStr(b$, "Cont") 'aka 2nd-4th char's of Cont a$=a$+Mid(b$, place+7, 3) place=InStr(b$, "GPub") a$=a$+Mid(b$, place+7, 1) place=InStr(b$, "Conf") a$=a$+Mid(b$, place+7, 1) a$=a$+" " 'aka Titl page a$=a$+" " 'aka Index a$=a$+" " 'aka Cum Index place=InStr(b$, "Alph") a$=a$+Mid(b$, place+7, 1) place=InStr(b$, "S/L") a$=a$+Mid(b$, place+7, 1) Goto End008 Sco: place=InStr(b$, "Comp") a$=a$+Mid(b$, place+7, 2) place=InStr(b$, "FMus") 'aka Format a$=a$+Mid(b$, place+7, 1) a$=a$+" " 'aka Prts place=InStr(b$, "Audn") 'aka Int lvl a$=a$+Mid(b$, place+7, 1) place=InStr(b$, "Form") 'aka Repr a$=a$+Mid(b$, place+7, 1) place=InStr(b$, "AccM") a$=a$+Mid(b$, place+7, 6) place=InStr(b$, "LTxt") a$=a$+Mid(b$, place+7, 2) a$=a$+" " 'aka MEBE a$=a$+" " 'aka ??? a$=a$+" " Goto End008 Com: a$=a$+" " 'aka ??? a$=a$+" " '(3) place=InStr(b$, "Audn") a$=a$+Mid(b$, place+7, 1) a$=a$+" " 'Form, aka Repr [not used for COM in OCLC] a$=a$+" " '(2) place=InStr(b$, "File") a$=a$+Mid(b$, place+7, 1) a$=a$+" " a$=a$+" " 'aka GPub? a$=a$+" " '(6) Goto End008 Vis: place=InStr(b$, "Time") 'aka Leng a$=a$+Mid(b$, place+7, 3) a$=a$+" " 'aka InLC place=InStr(b$, "Audn") 'aka Int Lvl a$=a$+Mid(b$, place+7, 1) a$=a$+" " 'Mid(b$, place+7, 5) 'aka AccM place=InStr(b$, "GPub") a$=a$+Mid(b$, place+7, 1) place=InStr(b$, "Form") a$=a$+Mid(b$, place+7, 1) a$=a$+" " '(2) [previously 3] a$=a$+" " 'aka MEBE place=InStr(b$, "TMat") a$=a$+Mid(b$, place+7, 1) place=InStr(b$, "Tech") a$=a$+Mid(b$, place+7, 1) Goto End008 Rec: place=InStr(b$, "Comp") a$=a$+Mid(b$, place+7, 2) place=InStr(b$, "FMus") a$=a$+Mid(b$, place+7, 1) a$=a$+" " 'aka Prts place=InStr(b$, "Audn") 'aka Int Lvl a$=a$+Mid(b$, place+7, 1) place=InStr(b$, "Form") 'aka Repr a$=a$+Mid(b$, place+7, 1) place=InStr(b$, "AccM") a$=a$+Mid(b$, place+7, 6) place=InStr(b$, "LTxt") a$=a$+Mid(b$, place+7, 2) a$=a$+" " 'aka MEBE a$=a$+" " '(2) Goto End008 Map: place=InStr(b$, "Relf") a$=a$+Mid(b$, place+7, 4) a$=a$+" " 'Mid(b$, place+7, 1) 'aka 1st character of Base; aka Prme place=InStr(b$, "Proj") 'aka 2nd-3rd char's of Base a$=a$+Mid(b$, place+7, 2) place=InStr(b$, "CrTp") 'aka RecG a$=a$+Mid(b$, place+7, 1) a$=a$+" " '(2) place=InStr(b$, "GPub") a$=a$+Mid(b$, place+7, 1) a$=a$+" " '(2) a$=a$+" " 'aka Indx? a$=a$+" " place=InStr(b$, "SpFm") 'aka Form a$=a$+Mid(b$, place+7, 2) Goto End008 End008: place=InStr(b$, "Lang") a$=a$+Mid(b$, place+7, 3) place=InStr(b$, "MRec") a$=a$+Mid(b$, place+7, 1) place=InStr(b$, "Srce") a$=a$+Mid(b$, place+7, 1) 'a$=a$+"\x09" DoIt: CCSFF.Send a$ CCSFF.Send "\r777\x09\x09\x09" CCSFF.Send "\r777\x09\x09\x09" End Sub