Macro to Display Ascii code of selected character:   Return to List

' (also provides some options concerning replacement)

Public Sub Main()
Dim Term$
Dim n
Dim Button
Dim Drctn
WordBasic.EditFindClearFormatting
WordBasic.EditReplaceClearFormatting
On Error GoTo BYE
Term$ = Left(Selection.Text, 1)
n = Asc(Term$)
MYEXIT:
WordBasic.BeginDialog 430, 168, "        Ascii Code Detection and Replacement"
    WordBasic.Text 10, 6, 339, 13, "The Ascii code of the selected character is: " + Str(n), "Text1"
    WordBasic.Text 10, 27, 268, 13, "Enter replacement character(s) ==>", "Text2"
    WordBasic.Text 78, 41, 83, 13, "(If desired)", "Text3"
    WordBasic.TextBox 235, 24, 77, 18, "TextBox2"
    WordBasic.GroupBox 13, 66, 225, 85, "Direction of Replacement:"
    WordBasic.OptionGroup "OptGrp1"
        WordBasic.OptionButton 23, 90, 155, 16, "Entire Document", "OptBtn1"
        WordBasic.OptionButton 23, 109, 155, 16, "Replace Upward", "OptBtn2"
        WordBasic.OptionButton 22, 126, 176, 16, "Replace Downward", "OptBtn3"
    WordBasic.OKButton 287, 77, 88, 21
    WordBasic.CancelButton 287, 108, 88, 21
WordBasic.EndDialog
Dim Dlg As Object: Set Dlg = WordBasic.CurValues.UserDialog
Button = WordBasic.Dialog.UserDialog(Dlg)
If Button = 0 Then GoTo BYE
If Dlg.OptGrp1 = 0 Then
    WordBasic.StartOfDocument
    Drctn = 0
ElseIf Dlg.OptGrp1 = 1 Then
    Drctn = 1
Else
    Drctn = 0
End If
If Len(Dlg.TextBox2) = 0 Then GoTo BYE
WordBasic.EditReplace Find:=Term$, Direction:=Drctn, _
    Replace:=Dlg.TextBox2, ReplaceAll:=1
BYE:
WordBasic.Cancel
End Sub

See also:
Cycling through a character string (in memory)
Determining the Datatype



Note to Webmaster