Di bawah ini merupakan fungsi untuk menghapus seluruh komentar yang terdapat dalam Visual Basic 6.0:
Option ExplicitDi bawah ini merupakan fungsi untuk menghapus seluruh jajaran kosong (blank line)
Function DeleteAllComment(sText As String) As String
Dim str As String
Dim vArray As Variant
Dim g As String
Dim i As Integer
Dim x As Integer
Dim w As Integer
Dim u As String
Dim y As Integer
str = sText
vArray = Split(str, vbCrLf)
For i = LBound(vArray) To UBound(vArray)
If Trim(Right(vArray(i), 1)) = "_" Then
Do While Trim(Right(vArray(i + w), 1)) = "_"
If w > 0 Then
vArray(i) = vArray(i) & Left(vArray(i + w), Len(vArray(i + w)) - 1) & " "
vArray(i + w) = "'"
Else
vArray(i) = Left(vArray(i), Len(vArray(i)) - 1)
End If
w = w + 1
Loop
vArray(i) = vArray(i) & Left(vArray(i + w), Len(vArray(i + w))) & " "
vArray(i + w) = "'"
End If
w = 0
y = InStr(1, vArray(i), Chr(34) & "'" & Chr(34))
x = InStr(1, vArray(i), "'")
If x > 0 Then
If (y = 0) Then
If Right(vArray(i), 1) = "_" Then
Do While Right(vArray(i + w), 1) = "_"
If w > 0 Then vArray(i + w) = "'"
w = w + 1
Loop
vArray(i + w) = "'"
End If
If Trim(Mid(vArray(i), 1, x)) <> "'" Then
If Right(Mid(vArray(i), 1, x), 1) = "'" Then
g = g & Left(Mid(vArray(i), 1, x), Len(Mid(vArray(i), 1, x)) - 1) & vbCrLf
Else
g = g & Mid(vArray(i), 1, x) & vbCrLf
End If
End If
Else
g = g & vArray(i) & vbCrLf
End If
Else
g = g & vArray(i) & vbCrLf
End If
Next
DeleteAllComment = g
End Function
Function DeleteBlankLine(sText As String) As StringCara penggunaan:
Dim str As String
Dim vArray As Variant
Dim i As Integer
Dim g As String
str = sText
vArray = Split(sText, vbCrLf)
For i = LBound(vArray) To UBound(vArray)
If Trim(vArray(i)) <> "" Then
g = g & vArray(i) & vbCrLf
End If
Next
DeleteBlankLine = g
End Function
Option Explicit
Private Sub Command1_Click()
Dim str As String
str = DeleteAllComment(Text1.Text)
Text2.Text = DeleteBlankLine(str)
End Sub