Clean Up is a program that will clean up and indent Run Basic code.
 ' --------------------------------------------------------
 ' Program: cleanUp.bas
 ' Author: Dan Kokenge
 ' This program will beautify RB programs
 ' supply program name in UPLOAD
 ' Output: program with same name placed in
 ' DefaultDir$ + "\public\"
 ' --------------------------------------------------------
 
 upload "Select Program to endow with beauty"; prog$
 if prog$ = "" then end
 
 print "Program:";prog$;" will be looken good"
 
 q1$      = chr$(34) + chr$(39)
 q2$      = chr$(39) + chr$(34)
 cr$      = chr$(13)
 lf$      = chr$(10)
 crlf$    = cr$;lf$
 lfcr$    = lf$;cr$
 
 ' -------------------------------
 ' file out in \public dir
 ' -------------------------------
 fileOut$ = DefaultDir$ + "\public\" + prog$
 print "File Out:";fileOut$
 OPEN fileOut$ for OUTPUT as    #fo
 
 ' -------------------------------
 ' open file in from upload
 ' -------------------------------
OPEN prog$ FOR binary as    #fi
fileLen    = LOF(#fi)
nProg$    = input$(#fi, fileLen) + cr$
lProg$    = lower$(nProg$)
lbeg      = 1
for  cpos   = 1 to len(lProg$)
     a1$    = mid$(lProg$,cpos,1)
     a2$    = mid$(lProg$,cpos,2)
     if a1$ = cr$ or a1$ = lf$ or a2$ = crlf$ or a2$ = lfcr$ then
            lineNum = lineNum + 1
            lend    = cpos - lbeg
            b$    = trim$(mid$(lProg$,lbeg,lend)) ' lower case line
        a$    = trim$(mid$(nProg$,lbeg,lend)) ' normal case line
        ' -------------------------------------------------
        ' delete junk character from normal Line
        ' -------------------------------------------------
        ePos    = len(a$)
        nLine$  = ""
        for i    = 1 to ePos
            x$ = mid$(a$,i,1)
            if x$ > chr$(31) and x$ < chr$(127) or x$ = chr$(9) then nLine$ = nLine$ + x$
            if nLine$ = chr$(9) then nLine$ = ""
        next i
        nLine$    = trim$(nLine$)
        ' --------------------------------------------------
        ' turn junk characters to spaces for lower case line
        ' --------------------------------------------------
        if instr(b$,"<script")  > 0 then noIndent = 1
             if instr(b$,"</script>") > 0 then noIndent = 0
             b$ = strRep$(b$,q1$,"x")
             b$ = strRep$(b$,q2$,"x")
        b$ = word$(b$,1,"'")
        ePos    = len(b$)
        lLine$  = ""
        for i    = 1 to ePos
            x$   = mid$(b$,i,1)
            if x$ < chr$(32) then
                lLine$    = lLine$ + " "
                else
                lLine$    = lLine$ + x$
            end if
        next i
        lLine$             = trim$(lLine$) + " "
        if noIndent        = 1 then goto [skipIndent]
        if left$(lLine$,5) = "next "   then indent = indent - 1
        if left$(lLine$,5) = "wend "   then indent = indent - 1
        if left$(lLine$,7) = "end if " then indent = indent - 1
 
        [skipIndent]
        tabs$ = ""
                dots$ = ""
        for i = 1 to indent
            tabs$ = tabs$ + chr$(9)
                        dots$ = dots$ + "."
        next i
        print noIndent;"|";indent;"|";using("####",lineNum);"|";using("#####",lbeg);"|";using("###",lend);"|";dots$;nLine$
 
        print    #fo,tabs$;nLine$
        ' --------------------------------------
        ' check for indent
        ' --------------------------------------
        if noIndent = 1 then goto [noInd]
        if left$(lLine$,2) = "if" then
            x$    = word$(lLine$,2," then ")
            x1$    = trim$(word$(x$,1,"'"))
            if x1$    = "" then indent = indent + 1
        end if
        if left$(lLine$,6) = "while " then indent = indent + 1
        if left$(lLine$,4) = "for "   then indent = indent + 1
        [noInd]
        lbeg = cpos + 1
    end if
next cpos
if indent <> 0 then print "Got indent problems"
close    #fi
close    #fo
 
wait
' --------------------------------
' string replace rep str with
' --------------------------------
FUNCTION strRep$(str$,rep$,with$)
ln  = len(rep$)
ln1 = ln - 1
i   = 1
while i <= len(str$)
    if mid$(str$,i,ln) = rep$ then
        strRep$ = strRep$ + with$
        i = i + ln1
    else
        strRep$ = strRep$ + mid$(str$,i,1)
    end if
i = i + 1
WEND
END FUNCTION