10-26-2024, 11:26 PM
(This post was last modified: 10-26-2024, 11:27 PM by PhilOfPerth.)
(10-26-2024, 11:03 PM)Pete Wrote: Basically that replace Rem with ' is what mine is essentially doing.
Now back in the day, we were a pretty tough bunch. Find one little oopsie in a routine and 10 members were eating your lunch! Ah, the good ol' days. No participation trophies.
Okay, I'll comprise, for our kids sake: @Dimster, here is a combo of Pete and Steve's remark remover. It uses Steve's new age QB64 cool way to look up your file, with my remove remarks code. It's EXCELLENT!
Code: (Select All)
_Title "Pete and Steve's Excellent Adventure"
Do
BasIn$ = _OpenFileDialog$("File to Remove Comments From", "", "*.bas|*.bi|*.bm", "QB64PE files", 0)
If BasIn$ <> "" Then
period = _InStrRev(BasIn$, ".")
BasOut$ = Left$(BasIn$, period - 1) + "_nc" + Mid$(BasIn$, period)
Open BasIn$ For Binary As #1
a$ = Space$(LOF(1))
Get #1, , a$
Close #1
Open BasOut$ For Output As #2
Do
i = i + 1
x$ = Mid$(a$, i, 1)
If Asc(x$) > 32 Then col = col + 1
x2$ = LCase$(Mid$(a$, i, 4))
If Mid$(x2$, 1, 1) = "'" Then
If LTrim$(Mid$(a$, i + 2, 1)) = "$" Then x2$ = ""
ElseIf x2$ = "rem " Then
If Mid$(a$, i + 4, 1) <> "$" Then x2$ = "'" Else x2$ = ""
End If
If LCase$(Mid$(a$, i, 5)) = "data " Then dta = -1
Select Case Mid$(x2$, 1, 1)
Case "'"
If quote = 0 And dta = 0 Then
q = InStr(i, a$ + Chr$(13), Chr$(13))
If col = 1 Then lineout% = 2 Else lineout% = 0
i = q + lineout% - 1
new$ = RTrim$(new$)
If Right$(new$, 1) = ":" Then
new$ = Mid$(new$, 1, Len(new$) - 1) ' Remove trailing colon.
End If
col = 0
_Continue
End If
Case Chr$(34)
If dta = 0 Then quote = 1 - quote
Case ":"
If dta Then dta = 0
Case Chr$(13), Chr$(10)
quote = 0: col = 0: dta = 0
End Select
new$ = new$ + x$
Loop Until i >= Len(a$)
Print #2, new$
Close #2: Exit Do
Else
Exit Do
End If
Loop
System
Well, it beats the hell out of anything Bill (Sheldon) and Ted (Clippy) could ever put together.
Pete
Very nice! But it would be nicer if it told you it was successful, and the name of the new file. I was looking at the one created prevously (by Steve's version), not realizing it had a different name, and could see no improvements..
Of all the places on Earth, and all the planets in the Universe, I'd rather live here (Perth, W.A.)
Please visit my Website at: http://oldendayskids.blogspot.com/
Please visit my Website at: http://oldendayskids.blogspot.com/