'MacroName:BrowseAuthority 'MacroDescription:Browses the Authority File for the text in a field or a selection ' within a field. ' ' This macro was written by Walter F. Nickeson, ' University of Rochester, Rochester, NY ' wnickeson@library.rochester.edu ' ' Last updated: 2 April 2009. ' Check for the latest versions of this and my other macros at ' http://docushare.lib.rochester.edu/docushare/dsweb/View/Collection-2556 ' Please e-mail me with bug reports or to suggest improvements. ' ' Works in Connexion client 2.10. ' '**************************************************************************************** ' How it works: In a bibliographic or authority record, select some text within a ' variable field, or simply click anywhere in a variable field, and run the macro. The ' macro will browse the authority file using the words in the selection, or using the ' whole field, if no text has been selected. When browsing by selection, the macro asks ' you to choose the appropriate authority file index; when browsing by field, the macro ' chooses the index according to the tag. (The macro will work with a 500 field in a ' bibliographic record, enabling checking the proper treatment of phrases such as "A ' Mentor book" or verifying series mistagged as notes.) ' ' If two or three words are selected, the macro will offer to invert the selection and ' browse by the last word (keeping together as one word those joined by a hyphen), on the ' assumption that a selection of two or three words is most likely to be a personal name; ' but the macro also offers the option of browsing the selection as given. Whether or not ' the selection is inverted, you choose whether to browse in the authority file by name, ' subject, or title. Note that when browsing by selection, the selection must be kept ' within a subfield. If a selection spans multiple subfields, the macro will ignore ' everything after the first subfield delimiter it finds. ' ' If the whole field is to be browsed (typically, to verify the heading, but also to ' verify the title portion of a name/title heading, or subdivisions of an existing ' subject heading), the macro offers a number of options. You may send the complete ' heading to browse, or only part of it. If you choose to browse on the main subject ' heading, the macro will offer to add the subject subdivisions (if present) as an ' expanded term to scan. To browse on a single subject subdivision, click anywhere in ' that subdivision, from the delimiter preceding it to the delimiter following it; you ' don't need to click on the actual text, so you can avoid the automatic search that ' would result if the subdivision was controlled. If the field contains only one subject ' subdivision, the position of the cursor when clicked is irrelevant. For corporate ' bodies, subfield $k (e.g., "Manuscript") is considered a title, and you may browse on ' that. ' ' The macro constructs a search string from the selection or from the text of the field ' (or subfield) to send as an authority browse. It "normalizes" the string, dropping and ' substituting characters, and, for browsing titles or title subfields, guesses at some ' initial articles--but please omit initial articles when selecting text. ' ' If no matching heading is found for a selection, and you need to add the name to a ' bibliographic record as a heading just as it appears, you can immediately use my macro ' "PasteInverted" to paste the name without having to select and copy it again. That ' macro also offers the option of inverting a term of two or three words before pasting. '**************************************************************************************** Option Explicit Global Answer% 'Variable for testing Global TestString$ 'Variable for testing Declare Function AddCancel( Id$, Action%, SValue& ) Declare Function GetFirstWord$( BaseString$ ) Declare Function TruncateString$( BaseString$ ) Sub Main Dim CS As Object Set CS = CreateObject("Connex.Client") Dim ArticleTest$ : ArticleTest$ = "" Dim ButtonText1$ Dim ButtonText2$ Dim ButtonText3$ Dim Char$ : Char$ = "" Dim DisplayText$ Dim DisplayTextInverted$ Dim DisplayTextName$ Dim DisplayTextSubj$ Dim DisplayTextTitle$ Dim FieldText$ : FieldText$ = "" Dim Indicators$ Dim Language$ : Language$ = "" Dim MainHeading$ Dim MusicTitleHeading$ Dim NamePortion$ : NamePortion$ = "" Dim RawString$ Dim Remainder$ Dim SearchString$ : SearchString$ = "" Dim SearchStringInverted$ Dim SelectedText$ : SelectedText$ = "" Dim SubdivSearchMsg$ Dim SubdivSearchString$ Dim SubfieldCode$ Dim Tag$ Dim TitleHeading$ Dim TitlePortion$ Dim WorkString$ Dim AsciiChar% Dim Col% : Col% = 0 Dim Filing% Dim FindHyphen% : FindHyphen% = 1 Dim FindSpace% : FindSpace% = 1 Dim InitialCursorPos% Dim LCSH% Dim LengthOfTitle% : LengthOfTitle% = 0 Dim RawStringLength% Dim Row% : Row% = 0 Dim Start% : Start% = 1 Dim SubfieldMarker% : SubfieldMarker% = 0 Dim SubjSubdivCount% : SubjSubdivCount% = 0 Dim SubjSubdivStart% : SubjSubdivStart% = 1 Dim TitleStart% : TitleStart% = 0 Dim TypeOfHeading% Dim WindowType% Dim WordCount% : WordCount% = 1 Dim i, j, k, m As Integer : i = 0 : j = 0 : k = 0 : m = 0 Dim AddChar : AddChar = TRUE Dim BuildSubdivString : BuildSubdivString = FALSE Dim Comma : Comma = FALSE Dim LCSubject : LCSubject = TRUE Dim NameTitle : NameTitle = FALSE Dim PersonalDates : PersonalDates = FALSE Dim SearchResult Dim SecondSubfield : SecondSubfield = FALSE Dim Selection : Selection = FALSE Dim SubdivIsGeog : SubdivIsGeog = FALSE Dim Subject : Subject = FALSE Dim SubjectSubdivs : SubjectSubdivs = FALSE Dim SubordinateUnit : SubordinateUnit = FALSE Dim Success ' First check to see if any text has been selected; if so, that will become the search ' string. This line must come first because any macro code preceding it seems to cause ' the loss of part of the selection Selection = CS.GetSelectedText( SelectedText$ ) Row% = CS.CursorRow Col% = CS.CursorColumn ' Put the selection on the clipboard for possible manipulation by the macro ' "PasteInverted" (useful for when the browse results in no authority record found) Clipboard.Clear Clipboard.SetText SelectedText$ ' Next make sure that the type of window is bibliographic or authority; if it is any ' other type, exit the macro WindowType% = CS.ItemType Select Case WindowType% Case -1, 5 To 13, 15 To 16, 21 To 24 MsgBox "This macro only works in bibliographic and authority records!", 48, "Wrong type of window" GoTo Done: End Select ' If the type of window is correct, then verify that the selection was not made in the ' fixed field or the tag or indicator cells of a variable field. For these locations, the ' Client automatically selects the element or the cell when it's first clicked. The test ' for these selections seems to be that the column position of any selected element in ' the fixed field is 0 and the column position of a selected tag cell is 1. If the tag or ' indicator cells are selected, assume the whole field is meant to be browsed upon, and ' ignore the selection. After this check, make sure the selection is limited to within ' one field; text that spans fields won't be considered. If the selection passes all ' these tests, proceed to normalize the string If Col% = 0 Then MsgBox "This macro only works in the variable fields.", 48, "Cursor in fixed field!" GoTo Done: ElseIf Selection = TRUE And Col% > 5 Then SelectedText$ = Trim$( SelectedText$ ) i = InStr( SelectedText$, Chr$( 13 ) ) If i <> 0 Then MsgBox "Please limit text selection to within one field only!", 48, "Selection spans multiple fields" GoTo Done: End If GoTo Normalize: ElseIf Selection = TRUE And Col% < 6 Then Selection = FALSE End If ' If no text has been selected, check that the cursor has not been placed in the fixed ' field. If so, the macro can proceed, using the whole field in which the cursor is ' placed as the browse string If CS.GetFieldLine ( Row%, FieldText$ ) = FALSE Then MsgBox "Either click in a variable field or select some text.", 48, "There is nothing for the macro to work with ..." GoTo Done: End If InitialCursorPos% = Col% - 6 ' Separate the tag and indicators from the text of the field and determine the type of ' heading: ' 0 = Subject ' 1 = Personal name ' 2 = Corporate name ' 3 = Conference name ' 4 = Uniform title Tag$ = Left$( FieldText$, 3 ) Indicators$ = Mid$( FieldText$, 4, 2 ) Select Case Tag$ Case "150", "151", "450", "451", "550", "551", "650", "651" ' --LC subject heading (or reference) TypeOfHeading% = 0 Subject = TRUE Case "653", "655" ' --Other types of subject headings TypeOfHeading% = 0 Subject = TRUE LCSubject = FALSE Case "100", "400", "700", "800" ' --Personal name heading, all records TypeOfHeading% = 1 Case "600" ' --Personal name heading as subject, all records TypeOfHeading% = 1 Subject = TRUE Case "500" ' --Personal name heading, authority records only; on bibliographic records, consider ' 500 to be a title field If WindowType% = 3 OR WindowType% = 4 Then TypeOfHeading% = 1 Else TypeOfHeading% = 4 Filing% = 0 End If Case "110", "410", "710", "810" ' --Corporate name heading, all records TypeOfHeading% = 2 Case "510" ' --Corporate name heading, authority records only If WindowType% = 3 OR WindowType% = 4 Then TypeOfHeading% = 2 Else GoTo Unsearchable: End If Case "610" ' --Corporate name heading as subject, all records TypeOfHeading% = 2 Subject = TRUE Case "111", "411", "711", "811" ' --Conference name heading, all records TypeOfHeading% = 3 Case "511" ' --Conference name heading, authority records only If WindowType% = 3 OR WindowType% = 4 Then TypeOfHeading% = 3 Else GoTo Unsearchable: End If Case "611" ' --Conference name heading as subject, all records TypeOfHeading% = 3 Subject = TRUE Case "130", "240", "430", "440", "490", "730", "740", "830" ' --Title heading; where present, get the indicator for non-filing characters TypeOfHeading% = 4 If Tag$ = "240" OR Tag$ = "430" OR Tag$ = "440" OR Tag$ = "830" Then Filing% = Val( Right$( Indicators$, 1 ) ) ElseIf Tag$ = "130" AND ( WindowType% = 3 OR WindowType% = 4 ) Then Filing% = Val( Right$( Indicators$, 1 ) ) ElseIf Tag$ = "490" Then Filing% = 0 Else Filing% = Val( Left$( Indicators$, 1 ) ) End If Case "530" ' --Title heading, authority records only If WindowType = 3 OR WindowType% = 4 Then TypeOfHeading% = 4 Else GoTo Unsearchable: End If Case "630" ' --Title heading as subject TypeOfHeading% = 4 Subject = TRUE Filing% = Val( Left$( Indicators$, 1 ) ) Case "180", "181", "182", "185", "480", "481", "482", "485", "580", "581", "582", "585" ' --Subject subdivisions SubdivSearchMsg$ = "To search this subject subdivision, select (highlight) the term and run the macro again, clicking the " & Chr$( 34 ) & "Subject" & Chr$( 34 ) & " browse button." MsgBox SubdivSearchMsg$, 48, "Subject subdivision search" GoTo Done: Case Else GoTo Unsearchable: End Select ' For title fields, strip initial articles, as determined by the ' indicator for non-filing characters If TypeOfHeading% = 4 Then FieldText$ = Mid$( FieldText$, 6 + Filing% ) Else FieldText$ = Mid$( FieldText$, 6 ) End If '**************************************************************************************** ' In this section of the macro, construct the search string '**************************************************************************************** Normalize: If Selection = FALSE Then RawString$ = FieldText$ Else RawString$ = SelectedText$ End If RawStringLength% = Len( RawString$ ) j = 1 ' Examine each character in the field to determine whether to add it to the search ' string, or how it affects what to do with succeeding characters. Rules for including, ' excluding, and converting characters are found in the superseded document Authorities ' User Guide, chapter 4, section 4, "Rules for Phrase Searches," which at the date of ' latest revision of this macro was still available at ' http://www.oclc.org/support/documentation/worldcat/authorities/userguide/phrase_srch_aug/phrase_srch_aug.htm ' Subsequent documentation has lost these details Do While j <= RawStringLength% Char$ = Mid$( RawString$, j, 1 ) AsciiChar% = Asc( Char$ ) Select Case AsciiChar% ' Numbers and text characters: include; convert lowercase to uppercase Case 48 to 57, 65 to 90 SearchString$ = SearchString$ & Char$ Case 97 to 122 SearchString$ = SearchString$ & Chr$( AsciiChar% - 32 ) ' Ampersand and musical flat and sharp signs: include Case 38, 169, 204 SearchString$ = SearchString$ & Char$ ' Parentheses: include, except when searching personal names Case 40, 41 If TypeOfHeading% <> 1 Then SearchString$ = SearchString$ & Char$ ' Some special characters: convert to space unless following a space Case 32, 46, 47, 58 To 63, 92, 138, 139, 154, 155, 170, 171 If Right$(SearchString$, 1) <> " " Then SearchString$ = SearchString$ & " " ' Commas: include the first comma in headings for personal names; otherwise exclude (this ' contradicts the directions given in the documentation noted above, which instructs to ' include the comma for headings in 150 and 151) Case 44 Comma = TRUE If TypeOfHeading% = 1 Then If InStr( 1, SearchString$, "," ) = 0 Then SearchString$ = SearchString$ & Char$ Else SearchString$ = SearchString$ & " " End If ' Hyphen: Include if browsing by selection, as it probably indicates a compound surname Case 45 If Selection Then SearchString$ = SearchString$ & Char$ Else If Right$(SearchString$, 1) <> " " Then SearchString$ = SearchString$ & " " End If ' Superscript, subscript numbers: convert to normal Case 128 to 137 Char$ = Chr( AsciiChar% - 80 ) SearchString$ = SearchString$ & Char$ Case 144 to 153 Char$ = Chr( AsciiChar% - 96 ) SearchString$ = SearchString$ & Char$ ' Special characters: substitute Case 161, 177 SearchString$ = SearchString$ & "L" Case 162, 172, 178, 188 SearchString$ = SearchString$ & "O" Case 163, 179, 186 SearchString$ = SearchString$ & "D" Case 164, 180 SearchString$ = SearchString$ & "TH" Case 165, 181 SearchString$ = SearchString$ & "AE" Case 166, 182 SearchString$ = SearchString$ & "OE" Case 173, 189 SearchString$ = SearchString$ & "U" Case 184 SearchString$ = SearchString$ & "I" ' Subfield delimiter: If the data is from a selection, close the search string. ' Otherwise, identify the subfield code, which determines subsequent actions to be taken; ' then increment the string marker to start adding the characters of the subfield when ' appropriate Case 223 If Selection Then GoTo TrimString: Else SubfieldCode$ = Mid$( RawString$, j + 1, 1 ) End If ' If the characters of the previous subfield have been excluded from the search string, ' start adding those of the current subfield If AddChar = FALSE Then AddChar = TRUE ' If at least one previous subfield $b has been found, and the present subfield is ' something else, assume that the corporate name is complete If SubordinateUnit = TRUE AND SubfieldCode$ <> "b" Then NamePortion$ = SearchString$ ' Assume that after subfield $d has been found for an X00 field, the name is complete If PersonalDates = TRUE And NamePortion$ = "" Then NamePortion$ = SearchString$ If Right$( SearchString$, 1 ) <> " " Then SearchString$ = SearchString$ & " " ' Rules for specific subfields Select Case SubfieldCode$ ' A subordinate unit of a conference name is included; otherwise, exclude subfield $e Case "e" If TypeOfHeading% <> 3 Then AddChar = FALSE Else SubfieldMarker% = Len( SearchString$ ) SecondSubfield = TRUE End If j = j + 2 ' Add subordinate units or personal numbers; for corporate names, mark the presence of a ' subfield $b, because when all instances of subfield $b have been found, the corporate ' name is complete Case "b" If TypeOfHeading% = 2 Then SubordinateUnit = TRUE If SecondSubfield = FALSE Then SubfieldMarker% = Len( SearchString$ ) SecondSubfield = TRUE End If j = j + 2 ' The following subfields should all be included; some of them may mark the end of the ' name portion of a heading Case "c", "d", "f", "n", "q", "l", "m", "n", "o", "r", "s" If TypeOfHeading% = 2 OR TypeOfHeading% = 3 Then If NamePortion$ = "" Then NamePortion$ = SearchString$ ElseIf TypeOfHeading% = 1 Then PersonalDates = TRUE End If If SecondSubfield = FALSE Then SubfieldMarker% = Len( SearchString$ ) SecondSubfield = TRUE End If j = j + 2 Case "p" If TypeOfHeading% = 2 OR TypeOfHeading% = 3 Then If NamePortion$ = "" Then NamePortion$ = SearchString$ ElseIf TypeOfHeading% = 1 Then PersonalDates = TRUE End If j = j + 2 ' Include subfield $g in a name/title field (e.g., the other ' party in a treaty) Case "g" If TypeOfHeading% = 4 And NameTitle = TRUE Then AddChar = TRUE j = j + 2 ' Include subfield $k for title fields, as a form subdivision; for corporate bodies, ' consider subfield $k to be a title (e.g., "Manuscript"); otherwise, exclude Case "k" If TypeOfHeading% = 4 Or NameTitle = TRUE Then AddChar = TRUE ElseIf TypeOfHeading% = 2 Then NameTitle = TRUE TitleStart% = Len( SearchString$ ) AddChar = TRUE NamePortion$ = SearchString$ Else AddChar = FALSE End If If SecondSubfield = FALSE Then SubfieldMarker% = Len( SearchString$ ) SecondSubfield = TRUE End If j = j + 2 ' Subject subdivisions: Verify that subfields $v and $x are actually subject subdivisions ' in subject fields! If they aren't, exclude them from the search string. Otherwise, ' construct a parallel search string from the characters of the subdivision by copying ' from the end of the main search string as it is constructed Case "v", "x", "y", "z" If WindowType% = 3 OR WindowType% = 4 Then 'In auth rec these are subject subdivs that mark the heading as subject If SubfieldCode$ = "v" Or SubfieldCode$ = "x" Then AddChar = TRUE Subject = TRUE SubjectSubdivs = TRUE SubjSubdivStart% = Len( SearchString$ ) End If Else 'in bib records these are subjects only if in a subject field (could be ISSN or volume number) If Subject = FALSE Then AddChar = FALSE Else AddChar = TRUE SubjectSubdivs = TRUE SubjSubdivStart% = Len( SearchString$ ) End If End If If NamePortion$ = "" Then NamePortion$ = SearchString$ If SecondSubfield = FALSE Then SubfieldMarker% = Len( SearchString$ ) SecondSubfield = TRUE End If If SubfieldCode$ = "z" Then If SubdivIsGeog = FALSE Then SubdivIsGeog = TRUE End If If SubjSubdivCount% > 0 And j - 2 >= InitialCursorPos% Then BuildSubdivString = FALSE Else SubdivSearchString$ = "" BuildSubdivString = TRUE End If SubjSubdivCount% = SubjSubdivCount% + 1 j = j + 2 ' Subfield $t identifies a name/title field Case "t" NameTitle = TRUE TitleStart% = Len( SearchString$ ) If NamePortion$ = "" Then NamePortion$ = SearchString$ If SecondSubfield = FALSE Then SubfieldMarker% = Len( SearchString$ ) SecondSubfield = TRUE End If j = j + 2 Case "w" If SubfieldMarker% = 0 Then SubfieldMarker% = Len( SearchString$ ) GoTo TrimString: ' All other subfields: end construction of the search string Case Else GoTo TrimString: End Select ' All other characters: omit from search string Case Else End Select ' If a subfield is to be excluded from the search string, remove the character just added If AddChar = FALSE Then SearchString$ = Left$( SearchString$, Len( SearchString$) - 1 ) ' If a subject subdivision is encountered, construct the search string for that, to ' search for it separately, if desired If BuildSubdivString = TRUE And Comma = FALSE Then SubdivSearchString$ = SubdivSearchString$ & Right$( SearchString$, 1 ) Comma = FALSE j = j + 1 Loop TrimString: ' Remove any initial or trailing spaces SearchString$ = Trim$( SearchString$ ) If Selection = TRUE Then GoTo SendSelection: '**************************************************************************************** ' For browsing by field '**************************************************************************************** ' For title fields, remove common initial articles If NameTitle = TRUE Then TitlePortion$ = Trim( Mid$( SearchString$, TitleStart% ) ) ElseIf TypeOfHeading% = 4 Then TitlePortion$ = SearchString$ End If If TitlePortion$ <> "" Then ArticleTest$ = GetFirstWord$( TitlePortion$ ) If CS.GetFixedField( "Lang", Language$ ) = TRUE Then Select Case ArticleTest$ Case "A ", "AN ", "THE " If Language$ = "eng" Or Language$ = "zxx" Then TitlePortion$ = Mid$( TitlePortion$, Len( ArticleTest$ ) + 1 ) Case "DAS ","DER ","DIE " If Language$ = "ger" Then TitlePortion$ = Mid$( TitlePortion$, Len( ArticleTest$ ) + 1 ) Case "L ", "LE ", "LES ", "UN ", "UNE " If Language$ = "fre" Then TitlePortion$ = Mid$( TitlePortion$, Len( ArticleTest$ ) + 1 ) Case "LAS ", "LOS ", "UN ", "UNA " If Language$ = "spa" Then TitlePortion$ = Mid$( TitlePortion$, Len( ArticleTest$ ) + 1 ) Case "I ", "IL ", "L ", "LE ", "LO ", "UN ", "UNA ", "UNO " If Language$ = "ita" Then TitlePortion$ = Mid$( TitlePortion$, Len( ArticleTest$ ) + 1 ) Case "LA " If Language$ = "ita" Or Language$ = "spa" Or Language$ = "fre" Then TitlePortion$ = Mid$( TitlePortion$, Len( ArticleTest$ ) + 1 ) End Select End If End If ' Choose the index label and send the search string ' If a name as a subject heading has no subdivisions, search it as a name rather than as ' a subject If TypeOfHeading% > 0 And SubjectSubdivs = FALSE Then Subject = FALSE ' Subject headings and subject subdivisions: If Subject = TRUE And NameTitle = FALSE Then If ( Mid$( Indicators$, 2 ) <> "0" Or LCSubject = FALSE ) And ( WindowType% < 3 OR WindowType% > 4 ) Then LCSH% = MsgBox( "This heading is not an LC subject heading. Continue search anyway?", 4, "Not an LC heading!" ) If LCSH% = 7 Then GoTo Done: End If ' Set the text of the buttons in the subject heading search dialog box. The first button ' searches the main heading only (a name, title, or subject term). The second button ' directs the search to include an expanded term (the rest of the heading after the main ' term). This section of the macro distinguishes between names, titles, and subjects, ' sets the text of the buttons, and separates main and expanded terms Select Case TypeOfHeading% Case 0 DisplayText$ = "&Main heading '" ButtonText2$ = "Main heading including subdivisions (&Expanded browse)" If SubfieldMarker% = 0 Then MainHeading$ = SearchString$ Remainder$ = "" Else MainHeading$ = Left$( SearchString$, SubfieldMarker% ) Remainder$ = Trim( Mid$( SearchString$, SubfieldMarker% ) ) End If Case 1 To 3 DisplayText$ = "&Name heading '" ButtonText2$ = "Name heading including subdivisions (&Expanded browse)" MainHeading$ = RTrim( NamePortion$ ) If SubjSubdivStart% = 0 Then Remainder$ = "" Else Remainder$ = Trim( Mid$( SearchString$, SubjSubdivStart% ) ) End If Case 4 DisplayText$ = "&Title heading '" ButtonText2$ = "Title heading including subdivisions (&Expanded browse)" If SubfieldMarker% = 0 Then MainHeading$ = SearchString$ Remainder$ = "" Else MainHeading$ = Left$( SearchString$, SubfieldMarker% ) Remainder$ = Trim( Mid$( SearchString$, SubfieldMarker% ) ) End If End Select ' The heading is split into words to fit unbroken words into the button DisplayText$ = DisplayText$ & TruncateString$( MainHeading$ ) ButtonText1$ = DisplayText$ & "' only" ' The third button in the subject heading search dialog box directs the search to be on ' the subject subdivision in which the cursor was placed, or the first subdivision ' following the main heading if the cursor was placed in the main heading. This section ' of the macro sets the text for that button If SecondSubfield = TRUE Then ButtonText3$ = "&Subdivision '" & Trim$( SubdivSearchString$ ) & "' only" Begin Dialog WholeOrPartSubj 256, 156, "Send subject string", .AddCancel Text 72, 10, 96, 14, "Choose whether to browse on ..." ButtonGroup .choice PushButton 24, 28, 208, 20, ButtonText1$ PushButton 24, 58, 208, 20, ButtonText2$ PushButton 24, 88, 208, 20, ButtonText3$ PushButton 48, 118, 160, 20, "&Cancel" CancelButton 1, 1, 1, 1, .Cancel End Dialog Dim SendStringSubj as WholeOrPartSubj On Error GoTo ErrorTrap: Dialog SendStringSubj Select Case SendStringSubj.choice ' Browse on main heading, or name portion of heading, only Case 0 If TypeOfHeading% = 1 OR TypeOfHeading% = 2 OR TypeOfHeading% = 3 OR PersonalDates = TRUE Then SearchString$ = NamePortion$ GoTo PlainName: ElseIf TypeOfHeading% = 4 Then SearchString$ = MainHeading$ If SubjSubdivCount% = 0 Then GoTo TitleField: Else SearchString$ = MainHeading$ End If If Len( SearchString$) > 128 Then SearchString$ = Left$( SearchString$, 128 ) SearchResult = CS.Browse( "AF", "su", SearchString$ ) If SearchResult = FALSE Then MsgBox "Sorry, the search failed.", 64, "Search failure" ' Browse on main heading but send expanded term to refine the browse Case 1 If TypeOfHeading% = 1 OR TypeOfHeading% = 2 OR TypeOfHeading% = 3 OR PersonalDates = TRUE Then SearchString$ = NamePortion$ Else SearchString$ = MainHeading$ End If If Len( SearchString$) > 128 Then SearchString$ = Left$( SearchString$, 128 ) SearchResult = CS.BrowseAuthorityExpanded( "0", "su", SearchString$, Remainder$ ) If SearchResult = FALSE Then MsgBox "Sorry, the search failed.", 64, "Search failure" ' Browse on subdivision only Case 2 SearchString$ = SubdivSearchString$ If Len( SearchString$) > 128 Then SearchString$ = Left$( SearchString$, 128 ) If SubdivIsGeog = TRUE Then SearchResult = CS.Browse( "AF", "su", SearchString$ ) Else SearchResult = CS.Browse( "AF", "sb", SearchString$ ) End If If SearchResult = FALSE Then MsgBox "Sorry, the search failed.", 64, "Search failure" ' Cancel browse! Case 3 GoTo Done: End Select GoTo Done: ' For name/title fields ElseIf NameTitle = TRUE Then GoTo NameTitleField: Else If Len( SearchString$) > 128 Then SearchString$ = Left$( SearchString$, 128 ) SearchResult = CS.Browse( "AF", "su", SearchString$ ) If SearchResult = FALSE Then MsgBox "Sorry, the search failed.", 64, "Search failure" GoTo Done: End If ' Corporate bodies: Choose whether to browse on the whole heading or just the main ' heading in subfield $a, when there are subordinate units in the name ElseIf TypeOfHeading% = 2 And NameTitle = FALSE Then If SubordinateUnit = TRUE Then Begin Dialog WholeOrPartCorp 256, 126, "Browse for form of corporate name", .AddCancel Text 72, 10, 96, 14, "Choose whether to browse on ..." ButtonGroup .choice PushButton 24, 28, 208, 20, "&Whole heading" PushButton 24, 58, 208, 20, "Subfield $&A only" PushButton 48, 88, 160, 20, "&Cancel" CancelButton 1, 1, 1, 1, .Cancel End Dialog Dim SendStringCorp as WholeOrPartCorp On Error GoTo ErrorTrap: Dialog SendStringCorp Select Case SendStringCorp.choice Case 0 GoTo PlainName: Case 1 SearchString$ = Left$( SearchString$, SubfieldMarker% ) GoTo PlainName: Case 2, 3 GoTo Done: End Select Else GoTo PlainName: End If ' Conference headings: Choose whether to browse on the whole name--including number, ' date, and place of conference--or just the base name of the conference ElseIf TypeOfHeading% = 3 Then Begin Dialog WholeOrPartConf 256, 126, "Browse for form of conference name", .AddCancel Text 72, 10, 96, 14, "Choose whether to browse on ..." ButtonGroup .choice PushButton 24, 28, 208, 20, "&Name of conference only" PushButton 24, 58, 208, 20, "&Whole heading" PushButton 48, 88, 160, 20, "&Cancel" CancelButton 1, 1, 1, 1, .Cancel End Dialog Dim SendStringConf as WholeOrPartConf On Error GoTo ErrorTrap: Dialog SendStringConf Select Case SendStringConf.choice Case 0 If NamePortion$ <> "" Then SearchString$ = Trim( NamePortion$ ) GoTo PlainName: Case 1 GoTo PlainName: Case 2, 3 GoTo Done: End Select ' Titles: ElseIf TypeOfHeading% = 4 Then If NameTitle = FALSE Then SearchString$ = TitlePortion$ TitleField: If Len( SearchString$) > 128 Then SearchString$ = Left$( SearchString$, 128 ) SearchResult = CS.Browse( "AF", "ti", SearchString$ ) If SearchResult = FALSE Then MsgBox "Sorry, the search failed.", 64, "Search failure" GoTo Done: ' Name/title headings: Choose whether to browse on the name portion of the heading or the ' title portion ElseIf NameTitle = TRUE Then NameTitleField: ' Set the text of the buttons in the dialog box MainHeading$ = Trim( NamePortion$ ) DisplayText$ = "&Name '" & TruncateString$( NamePortion$ ) & "' only" ButtonText1$ = DisplayText$ DisplayText$ = "" TitleHeading$ = Trim( TitlePortion$ ) ' Check for the musical flat and sharp signs, which do not display properly in the dialog ' box, requiring substitution of the words "flat" and "sharp" k = InStr( 1, TitleHeading$, Chr$( 169 ) ) If k <> 0 Then MusicTitleHeading$ = Left$( TitleHeading$, k - 1) & "-FLAT" & Mid$( TitleHeading$, k + 1 ) Else MusicTitleHeading$ = TitleHeading$ m = InStr( 1, TitleHeading$, Chr$( 204 ) ) If m <> 0 Then MusicTitleHeading$ = Left$( TitleHeading$, m - 1) & "-SHARP" & Mid$( TitleHeading$, m + 1 ) End If DisplayText$ = "&Title '" & TruncateString$( MusicTitleHeading$ ) & "' only" ButtonText2$ = DisplayText$ Begin Dialog NameOrTitle 256, 126, "Browse for name or title", .AddCancel Text 72, 10, 96, 14, "Choose whether to browse on ..." ButtonGroup .choice PushButton 24, 28, 208, 20, ButtonText1$ PushButton 24, 58, 208, 20, ButtonText2$ PushButton 48, 88, 160, 20, "&Cancel" CancelButton 1, 1, 1, 1, .Cancel End Dialog Dim SendStringName as NameOrTitle On Error GoTo ErrorTrap: Dialog SendStringName Select Case SendStringName.choice ' Search the name portion only Case 0 SearchString$ = Trim( Left$( SearchString$, TitleStart% ) ) GoTo PlainName: ' If the name/title field is a subject heading, remove any subject subdivisions and ' search the title part simply as a title Case 1 If SubjSubdivStart% <> 1 Then LengthOfTitle% = SubjSubdivStart% - TitleStart% - 1 SearchString$ = Trim( Left$( TitleHeading$, LengthOfTitle% ) ) Else SearchString$ = TitleHeading$ End If If Len( SearchString$) > 128 Then SearchString$ = Left$( SearchString$, 128 ) SearchResult = CS.Browse( "AF", "ti", SearchString$ ) If SearchResult = FALSE Then MsgBox "Sorry, the search failed.", 64, "Search failure" ' Cancel browse! Case 2, 3 GoTo Done: End Select GoTo Done: Else GoTo PlainName: End If ' A straightforward name browse PlainName: Select Case Tag$ Case "100", "400", "500", "600", "700", "800" If Len( SearchString$) > 128 Then SearchString$ = Left$( SearchString$, 128 ) SearchResult = CS.Browse( "AF", "pn", SearchString$ ) If SearchResult = FALSE Then MsgBox "Sorry, the search failed.", 64, "Search failure" Case "110", "410", "510", "610", "710", "810" If Len( SearchString$) > 128 Then SearchString$ = Left$( SearchString$, 128 ) SearchResult = CS.Browse( "AF", "co", SearchString$ ) If SearchResult = FALSE Then MsgBox "Sorry, the search failed.", 64, "Search failure" Case "111", "411", "511", "611", "711", "811" If Len( SearchString$) > 128 Then SearchString$ = Left$( SearchString$, 128 ) SearchResult = CS.Browse( "AF", "cn", SearchString$ ) If SearchResult = FALSE Then MsgBox "Sorry, the search failed.", 64, "Search failure" End Select GoTo Done: '**************************************************************************************** ' For when text within a field has been selected '**************************************************************************************** SendSelection: ' Count the words in the selection. If there are two or three, two search strings must be ' constructed, one of which puts the last word first, for browsing an inverted personal ' name Do FindSpace% = InStr( Start%, SearchString$, " " ) If FindSpace% > 1 Then WordCount% = WordCount% + 1 Start% = FindSpace% + 1 End If Loop Until FindSpace% = 0 ' Set the text of the buttons on the dialog boxes, invert the search string for ' selections of two or three words, and remove any hyphens from the search string. The ' search string and the button texts must be kept separate but worked on in parallel WorkString$ = SearchString$ DisplayText$ = TruncateString$( WorkString$ ) DisplayTextName$ = "&Name '" & DisplayText$ & "'" DisplayTextSubj$ = "&Subject '" & DisplayText$ & "'" DisplayTextTitle$ = "&Title '" & DisplayText$ & "'" If WordCount% = 2 Or WordCount% = 3 Then SearchStringInverted$ = Mid$( SearchString$, Start% - 1 ) & ", " & Left$( SearchString$, Start% - 1 ) WorkString$ = SearchStringInverted$ DisplayTextInverted$ = "&Inverted name '" & TruncateString$( WorkString$ ) & "'" FindHyphen% = InStr( SearchStringInverted$, "-" ) If FindHyphen% <> 0 Then SearchStringInverted$ = Left$( SearchStringInverted$, FindHyphen% - 1 ) & " " & Mid$( SearchStringInverted$, FindHyphen% + 1 ) GoTo Invert: End If FindHyphen% = InStr( SearchString$, "-" ) If FindHyphen% <> 0 Then SearchString$ = Left$( SearchString$, FindHyphen% - 1 ) & " " & Mid$( SearchString$, FindHyphen% + 1 ) ' The first dialog box covers selections of a single word or of more than three words Begin Dialog Uninverted 256, 156, "Choose how to browse Authority File", .AddCancel Text 84, 10, 82, 14, "Browse selected text as ..." ButtonGroup .choice PushButton 24, 28, 208, 20, DisplayTextName$ PushButton 24, 58, 208, 20, DisplayTextSubj$ PushButton 24, 88, 208, 20, DisplayTextTitle$ PushButton 48, 118, 160, 20, "&Cancel" CancelButton 1, 1, 1, 1, .Cancel End Dialog Dim FileToBrowse1 as Uninverted On Error GoTo ErrorTrap: Dialog FileToBrowse1 Select Case FileToBrowse1.choice Case 0 Success = CS.Browse ("AF", "nw", SearchString$) If Success = FALSE Then GoTo Failure: Case 1 Success = CS.Browse ("AF", "su", SearchString$) If Success = FALSE Then GoTo Failure: Case 2 Success = CS.Browse ("AF", "ti", SearchString$) If Success = FALSE Then GoTo Failure: End Select GoTo Done: ' The second dialog box covers a selection consisting of exactly two or three words. It ' includes an option to put the last word first, in order to browse a personal name given ' in normal form in the selection Invert: Begin Dialog Inverted 256, 186, "Choose how to browse Authority File", .AddCancel Text 84, 10, 82, 14, "Browse selected text as ..." ButtonGroup .choice PushButton 24, 28, 208, 20, DisplayTextInverted$ PushButton 24, 58, 208, 20, DisplayTextName$ PushButton 24, 88, 208, 20, DisplayTextSubj$ PushButton 24, 118, 208, 20, DisplayTextTitle$ PushButton 48, 148, 160, 20, "&Cancel" CancelButton 1, 1, 1, 1, .Cancel End Dialog Dim FileToBrowse2 as Inverted On Error GoTo ErrorTrap: Dialog FileToBrowse2 Select Case FileToBrowse2.choice Case 0 Success = CS.Browse ("AF", "nw", SearchStringInverted$) If Success = FALSE Then GoTo Failure: Case 1 Success = CS.Browse ("AF", "nw", SearchString$) If Success = FALSE Then GoTo Failure: Case 2 Success = CS.Browse ("AF", "su", SearchString$) If Success = FALSE Then GoTo Failure: Case 3 Success = CS.Browse ("AF", "ti", SearchString$) If Success = FALSE Then GoTo Failure: End Select GoTo Done: Failure: MsgBox "Sorry, could not execute the macro.", 64, "Search failure" GoTo Done: Unsearchable: MsgBox "This field does not contain a searchable heading. Try another field or select some text in this field.", 48, "Try again" GoTo Done: Done: Exit Sub ErrorTrap: If Err = 102 Then Exit Sub Else MsgBox "Error number " & Err & " occurred at line: " & Erl Resume Done End If End Sub '**************************************************************************************** ' Functions '**************************************************************************************** Function AddCancel( Id$, Action%, SValue& ) ' This function makes the pixel-square "CancelButton" in the dialog boxes invisible, so ' they can be closed with the [ESC] key or the X-close box in the corner while still ' retaining the hotkey enabled custom cancel button If Action% = 1 Then DlgVisible "Cancel", 0 End Function '**************************************************************************************** Function GetFirstWord$( BaseString$ ) ' This function returns the first word of a string ("BaseString$"), used to check (in a ' crude way) for the presence of an initial article in fields lacking a filing indicator Dim FirstWordMarker% FirstWordMarker% = InStr( BaseString$, " " ) If FirstWordMarker% <> 0 Then GetFirstWord$ = Left$( BaseString$, FirstWordMarker% ) Else GetFirstWord$ = "" End If End Function '**************************************************************************************** Function TruncateString$( BaseString$ ) ' This function breaks a string ("BaseString$") into words at the spaces in the string, ' and is used to extract portions of the search string to put on buttons in dialog boxes. ' Because Windows uses the ampersand to indicate a hot key, this function doubles it in ' order for it to display if it appears on a button Dim AmperStart% : AmperStart% = 1 Dim NumberOfWords% : NumberOfWords% = 1 Dim SpaceFinder% Dim StartInStr% : StartInStr% = 1 Dim TempString$ : TempString$ = "" Dim j Do SpaceFinder% = InStr( StartInStr%, BaseString$, " " ) If SpaceFinder% <> 0 Then NumberOfWords% = NumberOfWords% + 1 If SpaceFinder% > 35 Then TempString$ = Trim$( Left$( BaseString$, StartInStr% - 2 ) ) & " ..." Exit Do Else TempString$ = Trim$( BaseString$ ) End If StartInStr% = SpaceFinder% + 1 Else TempString$ = Trim$( BaseString$ ) End If Loop Until SpaceFinder% = 0 Do j = InStr( AmperStart%, TempString$, "&" ) If j <> 0 Then TempString$ = Left$( TempString$, j ) & "&" & Mid$( TempString$, j + 1 ) AmperStart% = j + 2 End If Loop Until j = 0 TruncateString$ = TempString$ End Function '**************************************************************************************** ' Some code for troubleshooting: ' ' TestString$ = SearchString$ ' Answer% = MsgBox( TestString$, 1) ' If Answer% = 2 Then GoTo Done: '****************************************************************************************