'MacroName:DeleteFields 'MacroDescription:Deletes multiple contiguous fields at once. ' ' This macro was written by Walter F. Nickeson, ' University of Rochester, Rochester, NY ' wnickeson@library.rochester.edu ' ' Last updated: 30 January 2008. ' 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: This macro deletes contiguous variable fields ' from a record in the Client without your having to worry about ' precise cursor placement in selecting those fields. Click ' anywhere in the first field to delete, and extend the ' selection by dragging straight down across all the fields you ' wish to delete, ending anywhere in the cell containing the ' last field to be deleted. (You can also select by dragging ' backward, or up.) You don't have to click at the beginning of ' the tag in the first field, and end the selection with the ' last character in the last field, or vice-versa. The macro ' deletes the whole of the fields in which the selection begins ' and ends (even though they may be only partially highlighted), ' and all fields in between. If only part of a cell has been ' selected, the whole field is deleted. ' ' The macro looks at the text that has been selected, figures ' out how many fields it spans, and uses the "DeleteFieldLine" ' command to delete that number of whole fields, starting with ' the first one. Using the macro command to cut whole fields ' gets around the problem of the key deleting only the ' characters that have been selected; as the Client functions ' now, to delete whole fields, the entire text of all the fields ' must be carefully selected, which requires more physical ' coordination and thought than it ought. '*************************************************************** Option Explicit Sub Main Dim CS As Object Set CS = CreateObject("Connex.Client") Dim EndOfField$ : EndOfField$ = Chr$( 013 ) & Chr$( 010 ) Dim SelectedText$ Dim BeginningRow% Dim CurrentRow% Dim Difference% Dim EndOfFieldCount% : EndOfFieldCount% = 0 Dim EndOfFieldFound% : EndOfFieldFound% = 0 Dim Start% : Start% = 1 Dim a Dim SelectedUp : SelectedUp = FALSE ' First, check to see that some text has been selected! If CS.GetSelectedText( SelectedText$ ) = FALSE Then MsgBox "Please select some fields to delete!", 64, "Macro needs a selection to delete" GoTo Done: End If CurrentRow% = CS.CursorRow ' If the selection has been made by dragging upward, the last ' characters will be the end-of-field marker (ASCII characters ' 013 + 010). In this case we must do some calculations to ' figure out in which row is the end of the selection If Right$( SelectedText$, 2 ) = EndOfField$ Then SelectedUp = TRUE ' Then find the end-of-field markers within the selection to ' count how many fields have been included. The macro will also ' work with a selection made in a single field; in that case, it ' will delete the whole field Do EndOfFieldFound% = InStr( Start%, SelectedText$, EndOfField$ ) If EndOfFieldFound% > 0 Then Start% = EndOfFieldFound% + 1 EndOfFieldCount% = EndOfFieldCount% + 1 End If Loop Until EndOfFieldFound% = 0 ' The Client can tell where the end of the selection is by the ' cursor position, so by knowing how many end-of-field markers ' there are we can work backwards to find the row where the ' selection begins If SelectedUp = TRUE Then CurrentRow% = CurrentRow% + EndOfFieldCount% Difference% = CurrentRow% - EndOfFieldCount% CurrentRow% = Difference% ' Delete each field in the selection, beginning with the first ' row. Of course, as each field is deleted, the next one will ' have the same line number, so the macro simply deletes the ' current row the same number of times as there are rows in the ' selection For a = 0 To ( EndOfFieldCount% ) If CS.DeleteFieldLine( CurrentRow% ) = FALSE Then MsgBox "Sorry, the macro failed to delete a field.", 16, "Macro failed" GoTo Done: End If Next a Done: End Sub