'MacroName:BatchChange 'MacroDescription:Do something to all selected records in a list 'Created by: Joel Hahn, Niles Public Library District 'Modified: 19 October 2004 'Last modified: 2 August 2013 Option Explicit Option Base 1 Type EditSelection EditType As String EditTag As String EditWhichInstances As String EditHowMuch As String EditSubfield As String AddData As String AddBeforeSubfield As String DelWhichSubfields As String FindText As String ReplaceText As String End Type Dim EditList$() Dim EditListComm() As EditSelection Dim AddTextList$ Dim AddCommList$ Dim AddComm as EditSelection Dim BlankOut as EditSelection Declare Function DlgFuncEditsEntry( WhichControl$, action%, suppvalue& ) As Integer Declare Sub Adds (EditData As EditSelection, CS as Object) Declare Sub Deletes (EditData As EditSelection, CS as Object) Declare Sub Finds (EditData As EditSelection, CS as Object) sub main Dim CS as Object Set CS = CreateObject("Connex.Client") Dim bool as Integer ReDim EditList$(1) ReDim EditListComm(1) 'If CS.IsOnline = FALSE Then ' If CS.Logon("","","") = FALSE Then ' MsgBox "Could not log on. Exiting..." ' Goto Done ' End If 'End If Select Case CS.ItemType Case -1 To 5, 9, 11 To 12, 14, 16 To 20 'If ((CS.ItemType > 6 And CS.ItemType < 8) Or (CS.ItemType = 10) Or (CS.ItemType = 13) Or (CS.ItemType) = FALSE Then '*** 6 = online bib brief list 7 = online bib save file list 8 = online bib constant data list, 10 = online authority brief list '*** 13 = online auth save file list, 15 = online auth constant data list, '*** 21 = local bib save file list, 22 = local auth save file list, 23 = local bib constant data list, 24 = local auth constant data list MsgBox "Not viewing the proper type of list. Exiting..." Goto Done 'End If End Select 'Dim i 'Dim NumRecs$(51) 'NumRecs$(1)="ALL" 'For i = 2 to 51 ' NumRecs$(i) = CStr(i-1) 'Next i ' 'Begin Dialog newdlg 187, 100, "Batch Change Records" ' Text 3, 5, 155, 10, "Enter MyStatus code used as selection indicator:" ' TextBox 9, 22, 162, 10, .MyStatus ' 'DropListBox 159, 3, 25, 150, MSArr(), .MyStatus ' 'CheckBox 5, 22, 165, 9, "Clear MyStatus of selected records when done", .ClearMS ' Text 7, 55, 174, 28, "If you have not yet given a unique MyStatus for the selected records, click Cancel, do that, then restart the macro." ' Text 8, 38, 123, 9, "Maximum number of records to check:" ' DropListBox 132, 37, 27, 159, NumRecs$(), .MaxRecs ' OkButton 73, 84, 50, 14 ' CancelButton 129, 84, 50, 14 'End Dialog ' 'Dim MSInfo as newdlg Dim retval 'retval = Dialog(MSInfo) 'If retval = 0 Then Goto Done GetChanges: Dim AddSel1$(4) AddSel1$(1) = "entire field" : AddSel1$(2) = "to field" : AddSel1$(3) = "to start of field" : AddSel1$(4) = "to end of field" Dim AddSel2$(3) AddSel2$(1) = "all instances of field" : AddSel2$(2) = "only first instance of field" : AddSel2$(3) = "only last instance of field" Dim AddSel3$(2) AddSel3$(1) = "before subfield" : AddSel3$(2) = "after subfield" Dim DelSel1$(3) DelSel1$(1) = "entire field" : DelSel1$(2) = "field, subfield" : DelSel1$(3) = "entire field if" Dim DelSel2$(3) DelSel2$(1) = AddSel2$(1) : DelSel2$(2) = AddSel2$(2) : DelSel2$(3) = AddSel2$(3) Dim DelSel3$(3) DelSel3$(1) = "all instances of subfield" : DelSel3$(2) = "only first instance of subfield" : DelSel3$(3) = "only last instance of subfield" Dim FindSel$(4) FindSel$(1) = "entire record" : FindSel$(2) = "all instances of field" : FindSel$(3) = "only first instance of field" : FindSel$(4) = "only last instance of field" Begin Dialog newdlg2 263, 202, "Edits Entry", .DlgFuncEditsEntry OptionGroup .Edits OptionButton 5, 5, 25, 10, "Add", .Add OptionButton 5, 50, 33, 10, "Delete", .Delete OptionButton 5, 80, 25, 10, "Find", .Find TextBox 35, 5, 200, 10, .AddData DropListBox 50, 20, 77, 59, AddSel1(), .AddSelection1 TextBox 130, 20, 20, 10, .AddTag DropListBox 154, 20, 97, 47, AddSel2(), .AddSelection2 DropListBox 50, 35, 77, 42, AddSel3(), .AddSelection3 TextBox 130, 35, 20, 10, .AddSubfield TextBox 40, 50, 20, 10, .DelTag DropListBox 65, 50, 77, 47, DelSel1(), .DeleteSelection1 TextBox 145, 50, 10, 10, .DelSubfield DropListBox 160, 50, 97, 47, DelSel2(), .DeleteSelection2 DropListBox 50, 65, 97, 47, DelSel3(), .DeleteSelection3 TextBox 151, 67, 64, 10, .DelFindWhat Text 219, 67, 35, 10, "is in field", .DeleteFindText TextBox 35, 80, 80, 10, .FindWhat Text 120, 80, 59, 10, "And replace it with", .FindText1 TextBox 180, 80, 70, 10, .ReplaceWith Text 55, 95, 10, 10, "in", .FindText2 DropListBox 70, 95, 112, 70, FindSel(), .FindSelection TextBox 185, 95, 20, 10, .FindTag Text 10, 115, 45, 10, "Current Edits:" ListBox 10, 130, 230, 45, EditList(), .EdList PushButton 175, 110, 65, 15, "&Add to Edit List", .AddList PushButton 10, 180, 67, 15, "&Delete from Edit List", .DelList OkButton 140, 180, 50, 14, .Ok CancelButton 195, 180, 50, 14, .Cancel End Dialog Dim ChangeInfo as newdlg2 retval = Dialog (ChangeInfo) If retval = 0 then Goto Done '***Note: -1 = OK, 0 = Cancel, 1 = AddList, 2 = DelList 'Goto Done MakeChanges: If EditListComm(1).EditType = "" Then MsgBox "You made no editing selections. Returning to selection window..." Goto GetChanges End If bool = CS.GetFirstSelectedItem If bool = FALSE then MsgBox "First selected record could not be opened. Exiting..." Goto Done End If Dim ListType$ Dim SaveNumber% 'Dim k Dim nextrec 'Dim CurMyStatus$ 'If MSInfo.MaxRecs=0 Then k=-1 Else k=1 nextrec=TRUE Do While (nextrec=TRUE) 'and (k<=MSInfo.MaxRecs) 'If (CS.ItemType < 0 or CS.ItemType > 4) or (CS.ItemType Then Select Case CS.ItemType Case -1 To 0, 5 To 16, Is >= 21 MsgBox "Active/top window is not a bibliographic, constant data, or authority record. Exiting..." Goto Done Case 1 To 4 ListType$ = "Online" Case 17 To 20 ListType$ = "Local" 'End If End Select 'bool = CS.QueryRecordStatus("MYSTATUS", CurMyStatus$) 'MsgBox "|" & CurMyStatus$ & "|" & MsInfo.MyStatus & "|" 'If CurMyStatus$ = MsInfo.MyStatus Then 'MSArr$(MSInfo.MyStatus) Then 'MsgBox k ' 'If MSInfo.ClearMS=1 Then bool = CS.SetMyStatus(" ") Dim CommandCount CommandCount = 1 Do Select Case EditListComm(CommandCount).EditType Case "A" 'MsgBox "Calling EditType Case A" '***** Call Adds(EditListComm(CommandCount), CS) Case "D" 'MsgBox "Calling EditType Case D" '***** Call Deletes(EditListComm(CommandCount), CS) Case "F" 'MsgBox "Calling EditType Case F" '***** Call Finds(EditListComm(CommandCount), CS) Case Else MsgBox "Edit type was improperly set for an edit request. Skipping to next request." Goto MiniLooper End Select MiniLooper: CommandCount = CommandCount + 1 Loop While CommandCount <= UBound(EditListComm) Looper: If ListType$ = "Online" Then bool = CS.SaveOnline Else SaveNumber% = CS.SaveToLocalFile(FALSE, FALSE) End If 'End If 'If MSInfo.MaxRecs >0 Then k=k+1 'If k<=MSInfo.MaxRecs Then nextrec = CS.GetNextSelectedItem If nextrec = FALSE Then Exit Do 'End If Loop bool = CS.CloseRecord(TRUE) MsgBox "Done!" Done: end sub Function DlgFuncEditsEntry( WhichControl$, action%, suppvalue& ) As Integer Dim place Dim tester$ Dim count Select Case action% Case 1 ' set up initial values displayed in dialog box If DlgValue("EdList")>=0 Then DlgValue "EdList", -1 End If DlgEnable "AddData", 1 DlgFocus "AddData" DlgEnable "AddSelection1", 1 DlgEnable "AddTag", 0 DlgEnable "AddSelection2", 0 DlgEnable "AddSelection3", 0 DlgEnable "AddSubfield", 0 DlgEnable "DelTag", 0 DlgEnable "DeleteSelection1", 0 DlgEnable "DelSubfield", 0 DlgEnable "DeleteSelection2", 0 DlgEnable "DeleteSelection3", 0 DlgEnable "DelFindWhat", 0 DlgEnable "DeleteFindText", 0 DlgEnable "FindWhat", 0 DlgEnable "ReplaceWith", 0 DlgEnable "FindSelection", 0 DlgEnable "FindTag", 0 DlgEnable "FindText1", 0 DlgEnable "FindText2", 0 Case 2 ' what to do if button or control value was changed (by clicking it) Select Case WhichControl$ Case "Add" DlgEnable "AddData", 1 DlgEnable "AddSelection1", 1 If DlgValue("AddSelection1") > 0 Then DlgEnable "AddTag", 1 DlgEnable "AddSelection2", 1 If DlgValue("AddSelection1") = 1 Then DlgEnable "AddSelection3", 1 DlgEnable "AddSubfield", 1 Else DlgEnable "AddSelection3", 0 DlgEnable "AddSubfield", 0 End If Else DlgEnable "AddTag", 0 DlgEnable "AddSelection2", 0 DlgEnable "AddSelection3", 0 DlgEnable "AddSubfield", 0 End If DlgEnable "DelTag", 0 DlgEnable "DeleteSelection1", 0 DlgEnable "DelSubfield", 0 DlgEnable "DeleteSelection2", 0 DlgEnable "DeleteSelection3", 0 DlgEnable "DelFindWhat", 0 DlgEnable "DeleteFindText", 0 DlgEnable "FindWhat", 0 DlgEnable "ReplaceWith", 0 DlgEnable "FindSelection", 0 DlgEnable "FindText1", 0 DlgEnable "FindText2", 0 DlgEnable "FindTag", 0 DlgFocus "AddData" Case "Delete" DlgEnable "AddData", 0 DlgEnable "AddSelection1", 0 DlgEnable "AddTag", 0 DlgEnable "AddSelection2", 0 DlgEnable "AddSelection3", 0 DlgEnable "AddSubfield", 0 DlgEnable "DelTag", 1 DlgEnable "DeleteSelection1", 1 DlgEnable "DeleteSelection2", 1 If DlgValue("DeleteSelection1") = 0 Then DlgEnable "DeleteSelection3", 0 DlgEnable "DelSubfield", 0 DlgEnable "DelFindWhat", 0 DlgEnable "DeleteFindText", 0 ElseIf DlgValue("DeleteSelection1") = 1 Then DlgEnable "DeleteSelection3", 1 DlgEnable "DelSubfield", 1 DlgEnable "DelFindWhat", 0 DlgEnable "DeleteFindText", 0 ElseIf DlgValue("DeleteSelection1") = 2 Then DlgEnable "DeleteSelection3", 0 DlgEnable "DelSubfield", 0 DlgEnable "DelFindWhat", 1 DlgEnable "DeleteFindText", 1 Else DlgEnable "DeleteSelection3", 0 DlgEnable "DelSubfield", 0 DlgEnable "DelFindWhat", 0 DlgEnable "DeleteFindText", 0 End If DlgEnable "FindWhat", 0 DlgEnable "ReplaceWith", 0 DlgEnable "FindSelection", 0 DlgEnable "FindText1", 0 DlgEnable "FindText2", 0 DlgEnable "FindTag", 0 DlgFocus "DelTag" Case "Find" DlgEnable "AddData", 0 DlgEnable "AddSelection1", 0 DlgEnable "AddTag", 0 DlgEnable "AddSelection2", 0 DlgEnable "AddSelection3", 0 DlgEnable "AddSubfield", 0 DlgEnable "DelTag", 0 DlgEnable "DeleteSelection1", 0 DlgEnable "DelSubfield", 0 DlgEnable "DeleteSelection2", 0 DlgEnable "DeleteSelection3", 0 DlgEnable "DelFindWhat", 0 DlgEnable "DeleteFindText", 0 DlgEnable "FindWhat", 1 DlgEnable "ReplaceWith", 1 DlgEnable "FindSelection", 1 DlgEnable "FindText1", 1 DlgEnable "FindText2", 1 If DlgValue("FindSelection") = 0 Then DlgEnable "FindTag", 0 Else DlgEnable "FindTag", 1 End If DlgFocus "FindWhat" Case "AddSelection1" If DlgValue("AddSelection1") = 0 Then DlgEnable "AddTag", 0 DlgEnable "AddSelection2", 0 DlgEnable "AddSelection3", 0 DlgEnable "AddSubfield", 0 Else DlgEnable "AddTag", 1 DlgEnable "AddSelection2", 1 If DlgValue("AddSelection1") = 1 Then DlgEnable "AddSelection3", 1 DlgEnable "AddSubfield", 1 Else DlgEnable "AddSelection3", 0 DlgEnable "AddSubfield", 0 End If End If Case "DeleteSelection1" If DlgValue("DeleteSelection1") = 0 Then DlgEnable "DeleteSelection3", 0 DlgEnable "DelSubfield", 0 DlgEnable "DelFindWhat", 0 DlgEnable "DeleteFindText", 0 ElseIf DlgValue("DeleteSelection1") = 1 Then DlgEnable "DeleteSelection3", 1 DlgEnable "DelSubfield", 1 DlgEnable "DelFindWhat", 0 DlgEnable "DeleteFindText", 0 ElseIf DlgValue("DeleteSelection1") = 2 Then DlgEnable "DeleteSelection3", 0 DlgEnable "DelSubfield", 0 DlgEnable "DelFindWhat", 1 DlgEnable "DeleteFindText", 1 Else DlgEnable "DeleteSelection3", 0 DlgEnable "DelSubfield", 0 DlgEnable "DelFindWhat", 0 DlgEnable "DeleteFindText", 0 End If Case "FindSelection" If DlgValue("FindSelection") = 0 Then DlgEnable "FindTag", 0 Else DlgEnable "FindTag", 1 End If Case "Ok", "Cancel" 'Do nothing & exit the dialog function Case "AddList" DlgFuncEditsEntry = TRUE Select Case DlgValue("Edits") Case 0 If Trim(DlgText("AddData")) = "" Then 'MsgBox "You did not enter any text to add" DlgFocus "AddData" Exit Function End If Case 1 If Trim(DlgText("DelTag")) = "" Then 'MsgBox "You did not enter a tag to delete" DlgFocus "DelTag" Exit Function End If Case 2 If Trim(DlgText("FindWhat")) = "" Then 'MsgBox "You did not enter any text to find" DlgFocus "FindWhat" Exit Function End If End Select If EditList$(1) <> "" Then ReDim Preserve EditList$(UBound(EditList$) + 1) ReDim Preserve EditListComm(UBound(EditListComm) + 1) Else ReDim Preserve EditList$(1) ReDim Preserve EditListComm(1) End If If DlgValue("Edits") = 0 Then '*** Add was selected AddTextList$ = "Add " AddComm.EditType = "A" AddComm.AddData = DlgText("AddData") Select Case DlgValue("AddSelection1") Case 0 AddTextList$ = AddTextList$ & "field: " & DlgText("AddData") 'AddCommList$ = AddCommList$ & DlgText("AddData") & "|0|ALL" AddComm.EditTag = "" AddComm.EditHowMuch = "ENTIRE" Case 1 AddTextList$ = AddTextList$ & Chr(34) & DlgText("AddData") & Chr(34) & " to" Select Case DlgValue("AddSelection2") Case 0 AddTextList$ = AddTextList$ & " all instances of " AddComm.EditWhichInstances = "ALL" Case 1 AddTextList$ = AddTextList$ & " the first " AddComm.EditWhichInstances = "FIRST" Case 2 AddTextList$ = AddTextList$ & " the last " AddComm.EditWhichInstances = "LAST" End Select AddTextList$ = AddTextList$ & Left(DlgText("AddTag") & "XXX", 3) & " field, " AddComm.EditTag = Left(DlgText("AddTag") & "XXX", 3) AddComm.EditHowMuch = "SUBFIELD" Select Case DlgValue("AddSelection3") Case 0 AddTextList$ = AddTextList$ & "before" AddComm.AddBeforeSubfield = "BEFORE" Case 1 AddTextList$ = AddTextList$ & "after" AddComm.AddBeforeSubfield = "AFTER" End Select AddTextList$ = AddTextList$ & " subfield " & DlgText("AddSubfield") AddComm.EditSubfield = DlgText("AddSubfield") Case 2 AddTextList$ = AddTextList$ & Chr(34) & DlgText("AddData") & Chr(34) & " to the start of" Select Case DlgValue("AddSelection2") Case 0 AddTextList$ = AddTextList$ & " all " & Left(DlgText("AddTag") & "XXX", 3) & " fields" AddComm.EditWhichInstances = "ALL" Case 1 AddTextList$ = AddTextList$ & " the first " & Left(DlgText("AddTag") & "XXX", 3) & " field" AddComm.EditWhichInstances = "FIRST" Case 2 AddTextList$ = AddTextList$ & " the last " & Left(DlgText("AddTag") & "XXX", 3) & " field" AddComm.EditWhichInstances = "LAST" End Select 'AddTextList$ = AddTextList$ & DlgText("AddData") AddComm.EditTag = Left(DlgText("AddTag") & "XXX", 3) AddComm.EditHowMuch = "START" Case 3 AddTextList$ = AddTextList$ & Chr(34) & DlgText("AddData") & Chr(34) & " to the end of" Select Case DlgValue("AddSelection2") Case 0 AddTextList$ = AddTextList$ & " all " & Left(DlgText("AddTag") & "XXX", 3) & " fields" AddComm.EditWhichInstances = "ALL" Case 1 AddTextList$ = AddTextList$ & " the first " & Left(DlgText("AddTag") & "XXX", 3) & " field" AddComm.EditWhichInstances = "FIRST" Case 2 AddTextList$ = AddTextList$ & " the last " & Left(DlgText("AddTag") & "XXX", 3) & " field" AddComm.EditWhichInstances = "LAST" End Select 'AddTextList$ = AddTextList$ & DlgText("AddData") AddComm.EditTag = Left(DlgText("AddTag") & "XXX", 3) AddComm.EditHowMuch = "END" End Select EditList$(UBound(EditList$)) = AddTextList$ EditListComm(UBound(EditListComm)) = AddComm DlgListBoxArray "EdList", EditList$ 'MsgBox "You want to Add a field" AddComm = BlankOut DlgText "AddData", "" DlgValue "AddSelection1", 0 DlgText "AddTag", "" DlgValue "AddSelection2", 0 DlgValue "AddSelection3", 0 DlgText "AddSubfield", "" DlgText "DelTag", "" DlgValue "DeleteSelection1", 0 DlgText "DelSubfield", "" DlgValue "DeleteSelection2", 0 DlgValue "DeleteSelection3", 0 DlgText "FindWhat", "" DlgText "ReplaceWith", "" DlgValue "FindSelection", 0 DlgText "FindTag", "" DlgEnable "AddData", 1 DlgEnable "AddSelection1", 1 DlgEnable "AddTag", 0 DlgEnable "AddSelection2", 0 DlgEnable "AddSelection3", 0 DlgEnable "AddSubfield", 0 DlgFocus "AddData" ElseIf DlgValue("Edits") = 1 Then '*** Delete was selected AddTextList$ = "Delete " 'AddCommList$ = "D|" AddComm.EditType = "D" Select Case DlgValue("DeleteSelection2") Case 0 If DlgValue("DeleteSelection1") = 0 or DlgValue("DeleteSelection1") = 2 Then AddTextList$ = AddTextList$ & "all instances of " Else AddTextList$ = AddTextList$ & "in each instance of " End If 'AddCommList$ = AddCommList$ & "ALL|" AddComm.EditWhichInstances = "ALL" Case 1 If DlgValue("DeleteSelection1") = 1 Then AddTextList$ = AddTextList$ & "in " AddTextList$ = AddTextList$ & "the first " 'AddCommList$ = AddCommList$ & "FIRST|" AddComm.EditWhichInstances = "FIRST" Case 2 If DlgValue("DeleteSelection1") = 1 Then AddTextList$ = AddTextList$ & "in " AddTextList$ = AddTextList$ & "the last " 'AddCommList$ = AddCommList$ & "LAST|" AddComm.EditWhichInstances = "LAST" End Select AddTextList$ = AddTextList$ & Left(DlgText("DelTag") & "XXX", 3) & " field" AddComm.EditTag = Left(DlgText("DelTag") & "XXX", 3) Select Case DlgValue("DeleteSelection1") Case 0 'AddCommList$ = AddCommList$ & DlgText("DelTag") & "|ALL" AddComm.EditHowMuch = "ENTIRE" Case 1 'AddCommList$ = AddCommList$ & DlgText("DelTag") & "|ALL|" & DlgText("DelSubfield") AddComm.EditHowMuch = "SUBFIELD" Select Case DlgValue("DeleteSelection3") Case 0 AddTextList$ = AddTextList$ & ", all instances of " 'AddCommList$ = AddCommList$ & "|ALL" AddComm.DelWhichSubfields = "ALL" Case 1 AddTextList$ = AddTextList$ & ", the first " 'AddCommList$ = AddCommList$ & "|FIRST" AddComm.DelWhichSubfields = "FIRST" Case 2 AddTextList$ = AddTextList$ & ", the last " 'AddCommList$ = AddCommList$ & "|LAST" AddComm.DelWhichSubfields = "LAST" End Select AddTextList$ = AddTextList$ & "subfield " & DlgText("DelSubfield") AddComm.EditSubfield = DlgText("DelSubfield") Case 2 'AddCommList$ = AddCommList$ & DlgText("DelTag") & "|ALL" AddComm.EditHowMuch = "ENTIRE" AddComm.FindText = DlgText("DelFindWhat") AddTextList$ = AddTextList$ & " if '" & DlgText("DelFindWhat") & "' is found in the field" End Select EditList$(UBound(EditList$)) = AddTextList$ EditListComm(UBound(EditListComm)) = AddComm DlgListBoxArray "EdList", EditList$ AddComm = BlankOut DlgText "AddData", "" DlgValue "AddSelection1", 0 DlgText "AddTag", "" DlgValue "AddSelection2", 0 DlgValue "AddSelection3", 0 DlgText "AddSubfield", "" DlgText "DelTag", "" DlgValue "DeleteSelection1", 0 DlgText "DelSubfield", "" DlgValue "DeleteSelection2", 0 DlgValue "DeleteSelection3", 0 DlgText "DelFindWhat", "" DlgText "FindWhat", "" DlgText "ReplaceWith", "" DlgValue "FindSelection", 0 DlgText "FindTag", "" DlgEnable "DelTag", 1 DlgEnable "DeleteSelection1", 1 DlgEnable "DelSubfield", 0 DlgEnable "DeleteSelection2", 1 DlgEnable "DeleteSelection3", 0 DlgEnable "DelFindWhat", 0 DlgEnable "DeleteFindText", 0 DlgFocus "DelTag" 'MsgBox "You want to Delete a field" Else '***Find was selected AddTextList$ = "Find " & Chr(34) & DlgText("FindWhat") & Chr(34) & " and replace it with " & Chr(34) & DlgText("ReplaceWith") & Chr(34) AddComm.EditType = "F" AddComm.FindText = DlgText("FindWhat") AddComm.ReplaceText = DlgText("ReplaceWith") Select Case DlgValue("FindSelection") Case 0 AddTextList$ = AddTextList$ & " in the entire record" AddComm.EditWhichInstances = "ALL" AddComm.EditHowMuch = "ENTIRE" AddComm.EditTag = "" Case 1 AddTextList$ = AddTextList$ & " in all " & Left(DlgText("FindTag") & "XXX", 3) & " fields" AddComm.EditWhichInstances = "ALL" AddComm.EditHowMuch = "TAG" AddComm.EditTag = Left(DlgText("FindTag") & "XXX", 3) Case 2 AddTextList$ = AddTextList$ & " in the first " & Left(DlgText("FindTag") & "XXX", 3) & " field" AddComm.EditWhichInstances = "FIRST" AddComm.EditHowMuch = "TAG" AddComm.EditTag = Left(DlgText("FindTag") & "XXX", 3) Case 3 AddTextList$ = AddTextList$ & " in the last " & Left(DlgText("FindTag") & "XXX", 3) & " field" AddComm.EditWhichInstances = "LAST" AddComm.EditHowMuch = "TAG" AddComm.EditTag = Left(DlgText("FindTag") & "XXX", 3) End Select EditList$(UBound(EditList$)) = AddTextList$ EditListComm(UBound(EditListComm)) = AddComm DlgListBoxArray "EdList", EditList$ AddComm = BlankOut DlgText "AddData", "" DlgValue "AddSelection1", 0 DlgText "AddTag", "" DlgValue "AddSelection2", 0 DlgValue "AddSelection3", 0 DlgText "AddSubfield", "" DlgText "DelTag", "" DlgValue "DeleteSelection1", 0 DlgText "DelSubfield", "" DlgValue "DeleteSelection2", 0 DlgValue "DeleteSelection3", 0 DlgText "FindWhat", "" DlgText "ReplaceWith", "" DlgValue "FindSelection", 0 DlgText "FindTag", "" DlgEnable "FindWhat", 1 DlgEnable "ReplaceWith", 1 DlgEnable "FindSelection", 1 DlgEnable "FindTag", 0 DlgEnable "FindText1", 1 DlgEnable "FindText2", 1 DlgFocus "FindWhat" 'MsgBox "You want to Edit a field" End If 'MsgBox "You clicked AddList" Case "DelList" DlgFuncEditsEntry = TRUE If EditList$(1) <> "" Or DlgValue("EdList") <> -1 Then Dim i If (DlgValue("EdList") + 1) < UBound(EditList$) Then For i = (DlgValue("EdList") + 1) To UBound(EditList$) - 1 EditList$(i) = EditList$(i + 1) EditListComm(i) = EditListComm(i + 1) Next Else EditList$(UBound(EditList$)) = "" EditListComm(UBound(EditListComm)) = BlankOut End If If UBound(EditList$) > 1 Then ReDim Preserve EditList$(UBound(EditList$) - 1) Else ReDim Preserve EditList$(1) End If If UBound(EditListComm) > 1 Then ReDim Preserve EditListComm(UBound(EditListComm) - 1) Else ReDim Preserve EditListComm(1) End If DlgListBoxArray "EdList", EditList$ End If 'MsgBox "You clicked DelList" End Select Case 3 ' what to do if text box [or list/combo box?] was changed (by clicking it or by typing in it) Select Case WhichControl$ End Select Case 4 ' what to do if control focus was changed (by leaving it and clicking elsewhere) Case 5 ' what to do while idle (repeated many times/sec) ' ' if some action is supposed to occur while the function is idle, ' then the following line must be used here: ' DlgFuncEditsEntry = TRUE ' succeeded by source code for the action to perform ' (typical examples: timer, checking for user keystrokes, etc.) End Select End Function Sub Adds (EditData As EditSelection, CS as Object) Dim bool Dim bool2 Dim i Dim isave Dim indata$ Dim outdata$ Dim lt$ Dim rt$ Dim place Dim place2 'MsgBox "EditHowMuch: " & EditData.EditHowMuch & Chr(10) & "EditTag: " & "|" & EditData.EditTag & "|" & Chr(10) & "EditData: " & EditData.AddData If EditData.EditHowMuch = "ENTIRE" and EditData.EditTag = "" Then '*** add an entire new field bool = CS.AddField(999, EditData.AddData) 'MsgBox bool ElseIf EditData.EditHowMuch = "SUBFIELD" Then '*** Insert data before/after an existing subfield Select Case EditData.EditWhichInstances Case "ALL", "FIRST" i = 1 bool = CS.GetFieldLine(i, indata$) Do Until bool = FALSE If Left(indata$, Len(CStr(Val(EditData.EditTag)))) = CStr(Val(EditData.EditTag)) Or (Left(indata$, 3) = Left(EditData.EditTag, 3)) Then If InStr(indata$, Chr(223) & EditData.EditSubfield) Then place = InStr(indata$, Chr(223) & EditData.EditSubfield) If EditData.AddBeforeSubfield = "AFTER" Then place2 = InStr(place + 2, Chr(223)) If place2 = 0 Then place2 = Len(indata$) place = place2 End If If place = Len(indata$) Then outdata$ = Trim(indata$) & " " & Trim(EditData.AddData) Else outdata$ = Trim(Left(indata$, place-1)) & " " & Trim(EditData.AddData) & " " & Mid(indata$, place) End If bool2 = CS.SetFieldLine(i, outdata$) If EditData.EditWhichInstances = "FIRST" Then '*** stop before affecting any further fields Exit Do End If End If End If i = i + 1 bool = CS.GetFieldLine(i, indata$) Loop Case "LAST" i = 1 bool = CS.GetFieldLine(i, indata$) Do Until bool = FALSE If Left(indata$, Len(CStr(Val(EditData.EditTag)))) = CStr(Val(EditData.EditTag)) Or (Left(indata$, 3) = Left(EditData.EditTag, 3)) Then isave = i End If i = i + 1 bool = CS.GetFieldLine(i, indata$) Loop If isave > 0 Then bool = CS.GetFieldLine(isave, indata$) If InStr(indata$, Chr(223) & EditData.EditSubfield) Then place = InStr(indata$, Chr(223) & EditData.EditSubfield) If EditData.AddBeforeSubfield = "AFTER" Then place2 = InStr(place + 2, Chr(223)) If place2 = 0 Then place2 = Len(indata$) place = place2 End If If place = Len(indata$) Then outdata$ = Trim(indata$) & " " & Trim(EditData.AddData) Else outdata$ = Trim(Left(indata$, place-1)) & " " & Trim(EditData.AddData) & " " & Mid(indata$, place) End If bool2 = CS.SetFieldLine(isave, outdata$) End If End If End Select ElseIf EditData.EditHowMuch = "START" Then '*** Insert data at the start of an existing field Select Case EditData.EditWhichInstances Case "ALL", "FIRST" i = 1 bool = CS.GetFieldLine(i, indata$) Do Until bool = FALSE 'MsgBox CStr(i) & "|" & CStr(Val(EditData.EditTag)) & "|" & Left(indata$, Len(CStr(Val(EditData.EditTag)))) & "|" If Left(indata$, Len(CStr(Val(EditData.EditTag)))) = CStr(Val(EditData.EditTag)) Or (Left(indata$, 3) = Left(EditData.EditTag, 3)) Then outdata$ = Left(indata$, 5) & Trim(EditData.AddData) If Mid(indata$, 6, 1) <> Chr(223) Then outdata$ = outdata$ & " " & Chr(223) & "a " End If outdata$ = outdata$ & Mid(indata$, 6) bool2 = CS.SetFieldLine(i, outdata$) If EditData.EditWhichInstances = "FIRST" Then '*** stop before affecting any further fields Exit Do End If End If i = i + 1 bool = CS.GetFieldLine(i, indata$) Loop Case "LAST" i = 1 bool = CS.GetFieldLine(i, indata$) Do Until bool = FALSE If Left(indata$, Len(CStr(Val(EditData.EditTag)))) = CStr(Val(EditData.EditTag)) Or (Left(indata$, 3) = Left(EditData.EditTag, 3)) Then isave = i End If i = i + 1 bool = CS.GetFieldLine(i, indata$) Loop If isave > 0 Then bool = CS.GetFieldLine(isave, indata$) outdata$ = Left(indata$, 5) & EditData.AddData If Mid(indata$, 6, 1) <> Chr(223) Then outdata$ = outdata$ & Chr(223) & "a " End If outdata$ = outdata$ & Mid(indata$, 6) bool2 = CS.SetFieldLine(i, outdata$) End If End Select ElseIf EditData.EditHowMuch = "END" Then '*** Insert data at the end of an existing field Select Case EditData.EditWhichInstances Case "ALL", "FIRST" i = 1 bool = CS.GetFieldLine(i, indata$) Do Until bool = FALSE If Left(indata$, Len(CStr(Val(EditData.EditTag)))) = CStr(Val(EditData.EditTag)) Or (Left(indata$, 3) = Left(EditData.EditTag, 3)) Then outdata$ = indata$ If Right(indata$, 1) <> " " Then outdata$ = outdata$ & " " outdata$ = outdata$ & EditData.AddData bool2 = CS.SetFieldLine(i, outdata$) If EditData.EditWhichInstances = "FIRST" Then '*** stop before affecting any further fields Exit Do End If End If i = i + 1 bool = CS.GetFieldLine(i, indata$) Loop Case "LAST" i = 1 bool = CS.GetFieldLine(i, indata$) Do Until bool = FALSE If Left(indata$, Len(CStr(Val(EditData.EditTag)))) = CStr(Val(EditData.EditTag)) Or (Left(indata$, 3) = Left(EditData.EditTag, 3)) Then isave = i End If i = i + 1 bool = CS.GetFieldLine(i, indata$) Loop If isave > 0 Then bool = CS.GetFieldLine(isave, outdata$) If Right(outdata$, 1) <> " " and Left(EditData.AddData, 1) <> " " Then outdata$ = outdata$ & " " End If outdata$ = outdata$ & EditData.AddData bool2 = CS.SetFieldLine(isave, outdata$) End If End Select Else '*** If you get here, there's a problem. End If End Sub Sub Deletes (EditData As EditSelection, CS as Object) Dim bool Dim i Dim isave Dim indata$ 'Val(EditData.EditTag) Select Case EditData.EditHowMuch Case "ENTIRE" '*** delete entire tags Select Case EditData.EditWhichInstances Case "ALL", "FIRST" '*** delete all or the first instance of the tag or range of tags i = 1 bool = CS.GetFieldLine(i, indata$) Do Until bool = FALSE If Left(indata$, Len(CStr(Val(EditData.EditTag)))) = CStr(Val(EditData.EditTag)) Or (Left(indata$, 3) = Left(EditData.EditTag, 3)) Then If EditData.FindText = "" Or InStr(indata$, EditData.FindText) Then bool = CS.DeleteFieldLine(i) i = i - 1 End If If EditData.EditWhichInstances = "FIRST" Then '*** stop before affecting any further fields Exit Do End If End If i = i + 1 bool = CS.GetFieldLine(i, indata$) Loop Case "LAST" '*** delete only the last instance of the tag or range of tags i = 1 isave = 0 bool = CS.GetFieldLine(i, indata$) Do Until bool = FALSE If Left(indata$, Len(CStr(Val(EditData.EditTag)))) = CStr(Val(EditData.EditTag)) Or (Left(indata$, 3) = Left(EditData.EditTag, 3)) Then isave = i End If i = i + 1 bool = CS.GetFieldLine(i, indata$) Loop If isave > 0 Then bool = CS.DeleteFieldLine(isave) End Select Case "SUBFIELD" '*** delete parts of existing fields Dim bool2 Dim place Dim place2 Dim outdata$ Select Case EditData.EditWhichInstances Case "ALL", "FIRST" '*** delete subfield in all or the first instance of the tag or range of tags i = 1 bool = CS.GetFieldLine(i, indata$) Do Until bool = FALSE If Left(indata$, Len(CStr(Val(EditData.EditTag)))) = CStr(Val(EditData.EditTag)) Or (Left(indata$, 3) = Left(EditData.EditTag, 3)) Then bool2 = FALSE Select Case EditData.DelWhichSubfields Case "ALL", "FIRST" '*** delete all or the first instances of a subfield in a particular tag place = InStr(indata$, Chr(223) & EditData.EditSubfield) Do While place > 0 place2 = InStr(place +1, indata$, Chr(223)) If place2 > 0 Then outdata$ = Left(indata$, place-1) & Mid(indata$, place2 - 1) If Mid(outdata$, 6, 3) = Chr(223) & "a " Then outdata$ = Left(outdata$, 5) & Mid(outdata$, 9) End If bool2 = CS.SetFieldLine(i, outdata$) place = InStr(place2 + 2, indata$, Chr(223) & EditData.EditSubfield$) Else outdata$ = Trim(Left(indata$, place-1)) If Mid(outdata$, 6, 3) = Chr(223) & "a " Then outdata$ = Left(outdata$, 5) & Mid(outdata$, 9) End If bool2 = CS.SetFieldLine(i, outdata$) place = 0 End If If bool2 <> FALSE And EditData.DelWhichSubfields = "FIRST" Then Exit Do End If Loop Case "LAST" '*** delete only the last instance of a subfield in a particular tag '*** if there is only one, delete it place = Len(indata$) - 1 Do If Mid(indata$, place, 2) = Chr(223) & EditData.EditSubfield Then place2 = InStr(place + 1, indata$, Chr(223)) If place2 > 0 Then outdata$ = Left(indata$, place-1) & Mid(indata$, place2 - 1) If Mid(outdata$, 6, 3) = Chr(223) & "a " Then outdata$ = Left(outdata$, 5) & Mid(outdata$, 9) End If bool2 = CS.SetFieldLine(i, outdata$) Else outdata$ = Trim(Left(indata$, place-1)) If Mid(outdata$, 6, 3) = Chr(223) & "a " Then outdata$ = Left(outdata$, 5) & Mid(outdata$, 9) End If bool2 = CS.SetFieldLine(i, outdata$) End If Exit Do End If place = place - 1 Loop while place > 5 End Select If bool2 <> FALSE And EditData.EditWhichInstances = "FIRST" Then '*** stop before affecting any further fields in a record Exit Do End If End If i = i + 1 bool = CS.GetFieldLine(i, indata$) Loop Case "LAST" '*** delete subfield in the last instance of the tag or range of tags i = 1 isave = 0 bool = CS.GetFieldLine(i, indata$) Do Until bool = FALSE If Left(indata$, Len(CStr(Val(EditData.EditTag)))) = CStr(Val(EditData.EditTag)) Or (Left(indata$, 3) = Left(EditData.EditTag, 3)) Then isave = i End If i = i + 1 bool = CS.GetFieldLine(i, indata$) Loop bool = CS.GetFieldLine(isave, indata$) Do Until bool = FALSE If Left(indata$, Len(CStr(Val(EditData.EditTag)))) = CStr(Val(EditData.EditTag)) Or (Left(indata$, 3) = Left(EditData.EditTag, 3)) Then bool2 = FALSE Select Case EditData.DelWhichSubfields Case "ALL", "FIRST" '*** delete all or the first instance of a subfield in a particular tag place = InStr(indata$, Chr(223) & EditData.EditSubfield) Do While place > 0 place2 = InStr(place + 1, indata$, Chr(223)) If place2 > 0 Then outdata$ = Left(indata$, place-1) & Mid(indata$, place2 - 1) If Mid(outdata$, 6, 3) = Chr(223) & "a " Then outdata$ = Left(outdata$, 5) & Mid(outdata$, 9) End If bool2 = CS.SetFieldLine(isave, outdata$) place = InStr(place2 + 2, indata$, Chr(223) & EditData.EditSubfield$) Else outdata$ = Trim(Left(indata$, place-1)) If Mid(outdata$, 6, 3) = Chr(223) & "a " Then outdata$ = Left(outdata$, 5) & Mid(outdata$, 9) End If bool2 = CS.SetFieldLine(isave, outdata$) place = 0 End If If bool2 <> FALSE And EditData.DelWhichSubfields = "FIRST" Then '*** stop before affecting any further subfields in a tag Exit Do End If Loop Case "LAST" '*** delete only the last instance of a subfield in a particular tag '*** if there is only one, delete it place = Len(indata$) - 1 Do If Mid(indata$, place, 2) = Chr(223) & EditData.EditSubfield Then place2 = InStr(place + 1, indata$, Chr(223)) If place2 > 0 Then outdata$ = Left(indata$, place-1) & Mid(indata$, place2 - 1) If Mid(outdata$, 6, 3) = Chr(223) & "a " Then outdata$ = Left(outdata$, 5) & Mid(outdata$, 9) End If bool2 = CS.SetFieldLine(isave, outdata$) Else outdata$ = Trim(Left(indata$, place-1)) If Mid(outdata$, 6, 3) = Chr(223) & "a " Then outdata$ = Left(outdata$, 5) & Mid(outdata$, 9) End If bool2 = CS.SetFieldLine(isave, outdata$) End If Exit Do End If place = place - 1 Loop while place > 5 End Select If bool2 <> FALSE And EditData.EditWhichInstances = "FIRST" Then '*** stop before affecting any further fields in a record Exit Do End If End If i = i + 1 bool = CS.GetFieldLine(i, indata$) Loop End Select End Select End Sub Sub Finds (EditData As EditSelection, CS as Object) Dim bool Dim bool2 Dim i Dim isave Dim indata$ Dim outdata$ Dim lt$ Dim rt$ Dim place Select Case EditData.EditHowMuch Case "ENTIRE" '*** Find/Replace in the entire record '*** The following fails because it cannot match on subfield delimiters! 'bool = CS.ReplaceTextAll(EditData.FindText, EditData.ReplaceText, TRUE) '*** Since the preceding line fails to find delimiters, the rest of this code is necessary i = 1 bool = CS.GetFieldLine(i, indata$) Do Until bool = FALSE outdata$ = indata$ place = InStr(outdata$, EditData.FindText) Do While place > 0 If place > 1 Then outdata$ = Left(outdata$, place - 1) & EditData.ReplaceText & Mid(outdata$, place + Len(EditData.FindText)) Else outdata$ = EditData.ReplaceText & Mid(outdata$, place + Len(EditData.FindText)) End If place = InStr(place + Len(EditData.ReplaceText), outdata$, EditData.FindText) Loop If outdata$ <> indata$ Then bool2 = CS.SetFieldLine(i, outdata$) End If i = i + 1 bool = CS.GetFieldLine(i, indata$) Loop '*** The above code is necessary because CS.ReplaceTextAll fails to find delimiters Case "TAG" Select Case EditData.EditWhichInstances Case "ALL", "FIRST" '*** Find/Replace in all or first instance of a particular tag or range of tags i = 1 bool = CS.GetFieldLine(i, indata$) Do Until bool = FALSE If Left(indata$, Len(CStr(Val(EditData.EditTag)))) = CStr(Val(EditData.EditTag)) Or (Left(indata$, 3) = Left(EditData.EditTag, 3)) Then outdata$ = indata$ place = InStr(outdata$, EditData.FindText) Do While place > 0 If place > 1 Then outdata$ = Left(outdata$, place - 1) & EditData.ReplaceText & Mid(outdata$, place + Len(EditData.FindText)) Else outdata$ = EditData.ReplaceText & Mid(outdata$, place + Len(EditData.FindText)) End If place = InStr(place + Len(EditData.ReplaceText), outdata$, EditData.FindText) Loop bool2 = CS.SetFieldLine(i, outdata$) If EditData.EditWhichInstances = "FIRST" Then '*** stop before affecting any further fields Exit Do End If End If i = i + 1 bool = CS.GetFieldLine(i, indata$) Loop Case "LAST" '*** Find/Replace in only the last instance of a particular tag or range of tags i = 1 isave = 0 bool = CS.GetFieldLine(i, indata$) Do Until bool = FALSE If Left(indata$, Len(CStr(Val(EditData.EditTag)))) = CStr(Val(EditData.EditTag)) Or (Left(indata$, 3) = Left(EditData.EditTag, 3)) Then isave = i End If i = i + 1 bool = CS.GetFieldLine(i, indata$) Loop If isave > 0 Then bool = CS.GetFieldLine(isave, indata$) outdata$ = indata$ place = InStr(outdata$, EditData.FindText) Do While place > 0 If place > 1 Then outdata$ = Left(outdata$, place - 1) & EditData.ReplaceText & Mid(outdata$, place + Len(EditData.FindText)) Else outdata$ = EditData.ReplaceText & Mid(outdata$, place + Len(EditData.FindText)) End If place = InStr(place + Len(EditData.ReplaceText), outdata$, EditData.FindText) Loop bool = CS.SetFieldLine(isave, outdata$) End If End Select End Select End Sub