' MacroName: Interface ' MacroDescription: Export a recort and manipulate Libs+ ' Save & Message Files ' Macro written by: Joel Hahn, Niles Public Library District 'Note: This macro will NOT work as is with the Interface II 'software (the version with batch interface capability)! sub main Dim CS as Session Set CS=CurrentSession Dim C() 'Count for # of existing export files Expo=0 : Backup=0 On Error Goto ErrHand 'Warning: 'Warn$="Make sure the attached printer is turned on. Macro " 'Warn$=Warn$+"will not work properly unless printer is " 'Warn$=Warn$+"ready to print." 'MsgBox Warn$, 48, " " GetOCLCNumAndTitle: CS.GetTextInRegion ONum$, 6, 10, 6, 17 SRow%=6 : SCol%=1 If CS.Find(" 245 ", SRow%, SCol%) Then CS.GetTextInRegion Title$, SRow%, 16, SRow%, 53 Else CS.PutText "PDN", 1, 1 RunMacro "PRSMUTIL!SendCommand" SRow%=6 : SCol%=1 CS.Find " 245 ", SRow%, SCol% CS.GetTextInRegion Title$, SRow%, 16, SRow%, 53 CS.PutText "HOME", 1, 1 RunMacro "PRSMUTIL!SendCommand" End If CS.PutText Chr$(0), 1, 1 Delim%=InStr(Title$, Chr(223)) EndLine%=InStr(Title$, Chr(221)) If Delim%>0 Then Title$=RTrim(Left(Title$, Delim%-1)) End If If EndLine%>0 Then Title$=RTrim(Left(Title$, EndLine%-1)) End If Exporter: directory=Dir ("C:\OCLCAPPS\PASSPORT\*.*") Do While directory<>"" If directory="EXPORT.DAT" Then Kill "C:\OCLCAPPS\PASSPORT\EXPORT.DAT" directory=Dir Loop CS.PutText "xpo", 1, 1 RunMacro "PRSMUTIL!SendCommand" Expo=1 CS.Receive 30, "USMARC" CS.PutText "s", 1, 1 RunMacro "PRSMUTIL!SendCommand" 'CS.Receive 30, "Under" 'CS.Receive 10, "." 'SR%=1 : SC%=1 'CS.Find " ", SR%, SC% 'CS.PutText " ", 1, 1 'CS.MoveCursor 1, 1 CS.PutText Chr$(0), 1, 1 GetXpoData: XpoFile$="C:\OCLCAPPS\PASSPORT\EXPORT.DAT" GetNextFileNum: count=1 ReDim C(1004) directory=Dir ("X:\CLSI\ONLINE\OCLC\*.*") Do While directory<>"" C(count)=directory count=count+1 directory=Dir Loop count2=1 : NFileNum=0 Do While count2<=count v=Val(C(count2)) If v>NFileNum then NFileNum=v count2=count2+1 Loop NFileNum=NFileNum+1 ' If NFileNum=99 Then ' If NFileNum=999 Then ' MsgBox "You must transfer records and clear the interface save file before sending another record." ' End If MakeBackups: MsgFile$="X:\CLSI\ONLINE\OCLC\OCMSG.DAT" MsgYes=0 directory=Dir ("X:\CLSI\ONLINE\OCLC\*.*") Do While directory<>"" If directory="OCMSG.DAT" Then MsgYes=1 directory=Dir Loop If MsgYes=0 Then OcMsgBackup$="X:\CLSI\ONLINE\OCMSG.DAT" FileCopy OcMsgBackup$, MsgFile$ End If Direc$="X:\CLSI\ONLINE\OCLC\" MsgFile$="OCMSG" SvFl$="OCSAVE" FileCopy Direc$+MsgFile$+".DAT", Direc$+MsgFile$+".BAK" FileCopy Direc$+SvFl$+".DAT", Direc$+SvFl$+".BAK" Backup=1 MakeNewXpoFile: OutFile$="X:\CLSI\ONLINE\OCLC\"+CStr(NFileNum) FileCopy XpoFile$, OutFile$ Kill "C:\OCLCAPPS\PASSPORT\EXPORT.DAT" Expo=0 OpenMsgFile: MsgFile$="X:\CLSI\ONLINE\OCLC\OCMSG.DAT" filenum%=FreeFile Open MsgFile$ For Append as filenum% ' Lock #filenum% ' "-- OC --" in following line originally "-- J2 --" Message$=" "+ONum$+" -- OC -- received "+Title$ Print #filenum%, Message$ ' Unlock #filenum% Close filenum% MakeSaveData: 'Date TodayDate=Date : TodayDate=Right("0"+TodayDate, 8) Lef=Left(TodayDate, 3) Rig=Right(TodayDate, Len(TodayDate)-3) : Rig=Right("0"+Rig, 5) TodayDate=Lef+Rig 'Time Tm=Time : PM=Right(Tm, 2) : h=InStr(Tm, ":") Hr=Val(Left(Tm, h-1)) : MinSec=Mid(Tm, h+1, 5) If PM="PM" and Hr<12 Then Hr=Hr+12 End If Hhr=CStr(Hr) Hhr=Right("0"+Hhr, 2) Tm=Hhr+":"+MinSec 'Special Characters CtrlC=Chr(3) : Nul=Chr(0) : HiChar$=Chr(255) 'Internal control number NFN=CStr(NFileNum) If Len(NFN)=1 Then NFN=Nul+NFN+Nul If Len(NFN)=2 Then NFN=Nul+NFN SaveDat$=CtrlC+NFN+Nul+Nul+ONum$+" " SaveDat$=SaveDat$+String(7, Nul) '+Nul+Nul+Nul+Nul+Nul+Nul+Nul SaveDat$=SaveDat$+TodayDate+" "+Tm+Nul+HiChar+HiChar SaveDat$=SaveDat$+String(17, " ")+Nul+"N***"+Nul+Nul '+" "+Nul+"N***"+Nul+Nul OpenSaveFile: SavFile$="X:\CLSI\ONLINE\OCLC\OCSAVE.DAT" filenum%=FreeFile Open SavFile$ For Binary As filenum% Len=66 ' Lock #filenum% If NFileNum=1 Then NumOffset=1 Else NumOffset=((NFileNum-1)*66)+1 End If Put #filenum%, NumOffset, SaveDat$ ' Unlock #filenum% Close filenum% PrintReceivedMessage: 'PrinterPort$="LPT1" 'filenum%=FreeFile 'Open PrinterPort$ for Append As filenum% ' Print #filenum%, Message$ 'Close #filenum% Extra=80-Len(Message$) Message$=Message$ + String(Extra," ")+Chr(13)+Chr(10) PrintBuffer Message$ Goto Done ErrHand: ErrMsg$="Interface Macro failed to complete successfully."+chr(10) ErrMsg$=ErrMsg$+"This record needs to be re-sent."+chr(10)+chr(10) MsgBox ErrMsg$+"Error(" & Err & ") on line #" & Erl & ": " & Error If Expo=1 Then Kill "C:\OCLCAPPS\PASSPORT\EXPORT.DAT" End If If Backup=1 Then FileCopy Direc$+MsgFile$+".BAK", Direc$+MsgFile$+".DAT" FileCopy Direc$+SvFl$+".BAK", Direc$+SvFl$+".DAT" directory=Dir ("X:\CLSI\ONLINE\OCLC\*.*") Do While directory<>"" If directory=CStr(NFileNum) Then Kill "X:\CLSI\ONLINE\OCLC\"+CStr(NFileNum) directory=Dir Loop End If Resume Done Done: end sub