Text center/highlighting

 BBS: Inland Empire Archive
Date: 03-19-92 (10:23)             Number: 136
From: TOM HAMMOND                  Refer#: NONE
  To: ALL                           Recvd: NO  
Subj: Text center/highlighting       Conf: (2) Quik_Bas
For anyone who might be able to use it, here's a routine I wrote several
years ago to permit me to easily center text on-screen AND to easily
highlight certain words within a line of text.

I'm sure it's not as professional as many would turn out, but it DOES
work and it saves me a lot of time now that it's available.

Maybey someone can make some use of it... or possibly improve upon it.

As usual, ya' gets what ya' pays for...


Tom Hammond      N0SS


DECLARE SUB ScrnCtr (Txt$, PTab%)         'Last touched:  03/19/92

Txt$ = "Testing {1}... {2}... {3}...   <Key> to continue...  <{Y>/N}
PTab% = 0
Call ScrnCtr

SUB ScrnCtr (Txt$, PTab%)
    'By:  Tom Hammond

    ' Text centering and hightlighting routine.

    ' Text enclosed by {}'s is highlighted WITHOUT the {}'s printed.
    ' Text enclosed by <>'s is highlighted WITH the <>'s printed,
    '   EXCEPT if text within the <>'s is enclosed by {}'s, in which
    '   case ONLY the text within {}'s is highlighted regardless of the
    '   <>'s (e.g. TxT$ = "<Y/{N}>", where only the 'N' is highlighted).

    ' PTab% is reset to zero after each pass through this routine.

    ' If the PTab% = 0 then TXT$ will be centered.
    ' If PTab% > 0 then centering will be bypassed and the PTAB% value
    '    will be used as a TAB value.
    ' If PTab% < 0 then NO centering or TABbing is done, TXT$ is parsed
    '    and printed at the current cursor position.

    DEFINT A-Z

    ' Check for matching Opening and Closing braces
    OBrace = 0
    CBrace = 0

    DO  'Count opening braces
        X = INSTR(X + 1, Txt$, "{")
        IF X THEN OBrace = OBrace + 1
    LOOP WHILE X

    DO  ' Count closing braces
        XBrace = INSTR(XBrace + 1, Txt$, "}")
        IF XBrace THEN CBrace = CBrace + 1
    LOOP WHILE XBrace

    IF OBrace - CBrace = 0 THEN Braces = OBrace + CBrace

    IF PTab% = 0 THEN
        LOCATE CSRLIN, INT((80 - LEN(Txt$) + Braces) / 2) + 1
    ELSEIF PTab% > 0 THEN
        LOCATE CSRLIN, PTab%
    END IF

    IF OBrace - CBrace <> 0 THEN GOTO PrintAsIs

    PTab% = 0
    Pointer = 1
    Parsed = 0

Parse1:      ' Parse text to locate delimiters
    OBrace = INSTR(Pointer, Txt$, "{")
    LTSymb = INSTR(Pointer, Txt$, "<")
    IF OBrace = 0 AND LTSymb = 0 AND Parsed = 0 THEN GOTO PrintAsIs

    Parsed = -1
    IF LTSymb AND OBrace = LTSymb + 1 THEN
        GOTO Parse3
    ELSEIF (LTSymb AND LTSymb < OBrace) OR (OBrace = 0 AND LTSymb) THEN
        GOTO Parse2
    ELSEIF (OBrace AND OBrace < LTSymb) OR (LTSymb = 0 AND OBrace) THEN
        GOTO Parse3
    END IF
    PRINT MID$(Txt$, Pointer, LEN(Txt$))
    EXIT SUB

Parse2:      'Highlight and print text, including the <> symbols
    IF LTSymb > 1 THEN
        PRINT MID$(Txt$, Pointer, LTSymb - Pointer + 1);
    ELSE
         PRINT LEFT$(Txt$, 1);
    END IF
    GTSymb = INSTR(LTSymb, Txt$, ">")

    'If there's an Open Brace WITHIN the <>'s, then don't highlight yet
    IF OBrace > 0 AND GTSymb > OBrace THEN
        PRINT MID$(Txt$, LTSymb + 1, OBrace - LTSymb - 1);
        Pointer = OBrace
        GOTO Parse3
    END IF
    COLOR 15
    PRINT MID$(Txt$, LTSymb + 1, GTSymb - LTSymb - 1);
    COLOR 7
    PRINT MID$(Txt$, GTSymb, 1);
    Pointer = GTSymb + 1
    GOTO Parse1

Parse3:      'Highlight and print text (only) within {} symbols
    IF OBrace > 1 THEN
        PRINT MID$(Txt$, Pointer, OBrace - Pointer);
    END IF
    COLOR 15
    CBrace = INSTR(OBrace, Txt$, "}")
    PRINT MID$(Txt$, OBrace + 1, CBrace - OBrace - 1);
    COLOR 7
    Pointer = CBrace + 1
    GOTO Parse1

PrintAsIs:   'Print entire line (no <'s OR {'s found)
    COLOR 7
    PRINT Txt$
    EXIT SUB

END SUB

-------------- CUT LINE --------------

---
 þ SLMR 2.1 þ All hope abandon, ye who enter messages here.


--- WM v2.00/91-0231
 * Origin: The Modem Zone BBS (314) 893-5106 (1:289/2)
Outer Court
Echo Basic Postings

Books at Amazon:

Back to BASIC: The History, Corruption, and Future of the Language

Hackers: Heroes of the Computer Revolution (including Tiny BASIC)

Go to: The Story of the Math Majors, Bridge Players, Engineers, Chess Wizards, Scientists and Iconoclasts who were the Hero Programmers of the Software Revolution

The Advent of the Algorithm: The Idea that Rules the World

Moths in the Machine: The Power and Perils of Programming

Mastering Visual Basic .NET