@Dimster
In it's simplest form...
Applied to remove lines that are completely remarked and to get rid of trailing colons...
I don't know if QB64 still uses that _ symbol to wrap a code line. If it does, that would have to be included in an analysis.
Play around with it, and let me know if there are any chinks in the armor.
Pete
In it's simplest form...
Code: (Select All)
Width 140, 42
_ScreenMove 0, 0
a$ = "i=0: Print " + Chr$(34) + "Don't!" + Chr$(34) + " ' Remove this " + Chr$(34) + " " + Chr$(34) + " ha!" + Chr$(13) + Chr$(10) + "Rem This " + Chr$(34) + "needs" + Chr$(34) + " to go, too!" + Chr$(13) + Chr$(10) + "Print " + Chr$(34) + "Aint that cool?" + Chr$(34)
Print a$
seed = 1
c = 0
Do
q = InStr(seed, LCase$(a$), "rem ")
If q Then
a$ = Mid$(a$, 1, q - 1) + "'" + Mid$(a$, q + 3) ' Convert Rem to '
Else
Exit Do
End If
c = c + 1: If c > Len(a$) Then Print "Error": End ' Prevents some fail that caused an endless loop.
seed = seed + 5
Loop
For i = 1 To Len(a$)
x$ = Mid$(a$, i, 1)
Select Case x$
Case "'"
If quote = 0 Then
Remove = 1 - Remove
End If
Case Chr$(34)
If Remove = 0 Then
quote = 1 - quote
End If
Case Chr$(13), Chr$(10)
Remove = 0: quote = 0
End Select
If Remove = 0 Then new$ = new$ + x$
Rem Line below can be used to see how it progresses.
' Print "Remove ="; Remove, "quote ="; quote, "x$ = "; x$, "new$ = "; new$ : Sleep
Next
Print new$
Applied to remove lines that are completely remarked and to get rid of trailing colons...
Code: (Select All)
Width 80, 37
_Font 16
_ScreenMove _Middle
Dim i As _Integer64
Dim col As Integer
For demo = 1 To 2
Color 3, 0: Print "DEMO"; demo; "WITH COMMENTS...": Print: Color 7, 0
If demo = 1 Then
a$ = "i=0: Print " + Chr$(34) + "Don't!" + Chr$(34) + " ' Remove this " + Chr$(34) + " " + Chr$(34) + " ha!" + Chr$(13) + Chr$(10) + "j = 0: Rem This " + Chr$(34) + "needs" + Chr$(34) + " to go, too!" + Chr$(13) + Chr$(10) + "Print " + Chr$(34) + "Aint that cool?" + Chr$(34)
Else
a$ = "i=0: Print " + Chr$(34) + "Don't!" + Chr$(34) + " ' Remove this " + Chr$(34) + " " + Chr$(34) + " ha!" + Chr$(13) + Chr$(10) + "Rem This " + Chr$(34) + "needs" + Chr$(34) + " to go, too!" + Chr$(13) + Chr$(10) + "Print " + Chr$(34) + "Aint that cool?" + Chr$(34)
End If
For w = 1 To Len(a$) ' This is just a little 1/2 ASCII routine to change the font color for remarks.
x$ = Mid$(a$, w, 1)
Select Case x$
Case "'", "R" ' R only appears as Rem in this play code, that's why we can get away with it in this demo.
If quote = 0 Then
Color 14, 0
End If
Case Chr$(34)
If Remove = 0 Then
quote = 1 - quote
End If
Case Chr$(13), Chr$(10)
Color 7, 0
End Select
If Mid$(a$, w, 1) = Chr$(13) Then
Print
ElseIf Mid$(a$, w, 1) = Chr$(10) Then
Print
Else
Print Mid$(a$, w, 1);
End If
Next
Color 7, 0
seed = 1
c = 0
Do
q = InStr(seed, LCase$(a$), "rem ")
If q Then
a$ = Mid$(a$, 1, q - 1) + "'" + Mid$(a$, q + 3) ' Convert Rem to '
Else
Exit Do
End If
c = c + 1: If c > Len(a$) Then Print "Error": End ' Prevents some fail that caused an endless loop.
seed = seed + 5
Loop
Print: Print
Remove = 0: quote = 0: col = 0: i = 0: new$ = ""
Do
i = i + 1: col = col + 1
x$ = Mid$(a$, i, 1)
Select Case x$
Case "'"
If quote = 0 Then
If quote = 0 Then
q = InStr(i, a$ + Chr$(13), Chr$(13))
If col = 1 Then
a$ = Mid$(a$, 1, i - 1) + Mid$(a$, q + 2)
i = i - 1: col = 0
Else
a$ = Mid$(a$, 1, i - 1) + Mid$(a$, q)
i = i - 1: col = 0
End If
If Mid$(a$, i - 2, 2) = ": " Then
new$ = Mid$(new$, 1, Len(new$) - 2) ' Remove trailing colon.
End If
_Continue
End If
End If
Case Chr$(34)
quote = 1 - quote
Case Chr$(13), Chr$(10)
quote = 0: col = 0
End Select
new$ = new$ + x$
Loop Until i >= Len(a$)
Color 3, 0: Print: Print "WITHOUT COMMENTS": Print: Color 7, 0
Print new$: Print
Print "-----------------------------------------------"
Next
I don't know if QB64 still uses that _ symbol to wrap a code line. If it does, that would have to be included in an analysis.
Play around with it, and let me know if there are any chinks in the armor.
Pete