|
25 Years of Programming
An open source source for C, C++, OWL, BASIC, MDB, XLS, DOT, and more... |
Home Projects Up Sitemap Search Blog Forum+Chat About Us Privacy Terms of Use Feedback FAQ Images Services Payments Humor Music |
Zero the parity bits of all bytes in a file - Word 2003 Visual Basic macroThis is yet another of my methods to zero the highest bit (the parity bit) of all characters in file so all the characters have ASCII values < 128. I had to do the procedure many times on log (capture buffer) files of modem sessions from the days when the parity bit was used for error checking, and when importing old WordStar files into Word. WordStar used the high bit to indicate whether it was ok to add or delete the spaces following a word when justifying the text (or something like that). Unfortunately, I found a note to myself saying this macro, translated from the functional Word 6.0 version, doesn't work in Word 2003. I put a note below at the error point. However, this macro is now obsolete, anyway. If you import a file into Word 2003 and select "encoded in US-ASCII" in the file conversion dialog box, it will do this conversion for you. |
Attribute VB_Name = "MapdownParityBits"
Public Sub MAIN()
Attribute MAIN.VB_Description = "Zeroes bit 8 (parity) of all chars in file so all chars have ascii values < 128. For cleaning up log files of modem sessions.\r\n"
Attribute MAIN.VB_ProcData.VB_Invoke_Func = "TemplateProject.MapdownParityBits.MAIN"
Dim a
Rem Copyright (C)1999 Steven Whitney.
Rem Initially published by http://25yearsofprogramming.com.
Rem Published under GNU GPL (General Public License) Version 3, with ABSOLUTELY NO WARRANTY.
Rem ZEROES HIGH BIT (PARITY) OF ALL CHARS IN FILE
Rem SO ALL CHARS HAVE ASCII VALUES < 128.
Rem You should normally run this macro FIRST (before any control char
Rem handling) on a newly imported file.
Rem
Rem DUE TO SOME AUTOMATIC FORMATTING DURING EDITCLEAR(),
Rem THIS MACRO DOES *NOT* PRESERVE THE INTEGRITY OF THE ORIGINAL FILE,
Rem DOING *ONLY* THE PARITY STRIPPING.
Rem
Rem IF THAT IS WHAT YOU NEED, USE MY PROGRAM MAPDOWN.EXE.
Rem 11-26-99
Rem ----------------------------------------------------------------------------
If WordBasic.MsgBox("Run this macro only on a file freshly imported from text into MSWord. Also, a better choice is the program MAPDOWN.EXE. Continue anyway?", 36) <> -1 Then GoTo Bye
Rem ---------------------------------------------------------------------
Rem SECTION NOT NOW USED. MACRO NOW *DOES* CONVERT THESE CHARS.
Rem DON'T CONVERT CERTAIN CHARS USED BY MSWORD. SEE CLEANSTRING$() HELP.
Rem If a <> 160 And a <> 172 And a <> 176 And a <> 182 And a <> 183 Then
Rem EndIf
Rem ---------------------------------------------------------------------
WordBasic.StartOfDocument
While Not WordBasic.AtEndOfDocument()
Rem 1/19/06 ==> The next line does not work in Word 2003.
Rem Some brief testing failed to find an easy fix.
a = Asc(WordBasic.[Selection$]())
If a > 127 Then
Rem IT ONLY WORKS RIGHT IF YOU INSERT FIRST, THEN DELETE.
Rem OTHERWISE, SOME SPACES BETWEEN WORDS GET REMOVED ENTIRELY.
Rem 'AND' IS MUCH FASTER THAN A - 128
WordBasic.Insert Chr(a And 127) 'INSERT ORIGINAL AT LEFT
WordBasic.WW6_EditClear 'REMOVE ORIGINAL CHAR
Else
WordBasic.CharRight
End If
Wend
WordBasic.StartOfDocument
Rem ---------------------------------------------------------------------
Bye:
End Sub
|
|
|
|
|
Copyright ©2010 Steven Whitney. Last modified Thu 10/21/2010 02:08:02 -0700. |
||