June 2018 Update

This commit is contained in:
Ingy döt Net 2018-06-22 20:57:24 +00:00
parent ba8067c3b7
commit 22f33d4004
5278 changed files with 84726 additions and 14379 deletions

View file

@ -0,0 +1,34 @@
Option Explicit
Sub Main()
'See Output #1
RemoveLines "C:\Users\" & Environ("username") & "\Desktop\foobar.txt", 11, 5
'See Output #2
RemoveLines "C:\Users\" & Environ("username") & "\Desktop\foobar.txt", 8, 5
'See Output #3
RemoveLines "C:\Users\" & Environ("username") & "\Desktop\foobar.txt", 3, 5
End Sub
Private Sub RemoveLines(StrFile As String, StartLine As Long, NumberOfLines As Long)
Dim Nb As Integer, s As String, count As Long, out As String
Nb = FreeFile
Open StrFile For Input As #Nb
While Not EOF(Nb)
count = count + 1
Line Input #Nb, s
If count < StartLine Or count >= StartLine + NumberOfLines Then
out = out & s & vbCrLf
End If
Wend
Close #Nb
If StartLine >= count Then
MsgBox "The file contains only " & count & " lines"
ElseIf StartLine + NumberOfLines > count Then
MsgBox "You only can remove " & count - StartLine & " lines"
Else
Nb = FreeFile
Open StrFile For Output As #Nb
Print #Nb, out
Close #Nb
End If
End Sub

View file

@ -0,0 +1,36 @@
Option Explicit
Sub Main()
'See Output First call
OtherWay "C:\Users\" & Environ("username") & "\Desktop\foobar.txt", 11, 5
'See Output Second call
OtherWay "C:\Users\" & Environ("username") & "\Desktop\foobar.txt", 8, 5
'See Output Third call
OtherWay "C:\Users\" & Environ("username") & "\Desktop\foobar.txt", 3, 5
End Sub
Private Sub OtherWay(StrFile As String, StartLine As Long, NumberOfLines As Long)
Dim Nb As Integer, s As String, arr, i As Long, out() As String, j As Long
Nb = FreeFile
Open StrFile For Input As #Nb
s = Input(LOF(1), #Nb)
Close #Nb
arr = Split(s, Chr(13))
If StartLine >= UBound(arr) + 1 Then
MsgBox "First call : " & vbCrLf & " The file contains only " & UBound(arr) + 1 & " lines"
ElseIf StartLine + NumberOfLines > UBound(arr) + 1 Then
MsgBox "Second call : " & vbCrLf & " You only can remove " & UBound(arr) + 1 - StartLine & " lines"
Else
For i = LBound(arr) To UBound(arr)
If i < StartLine - 1 Or i >= StartLine + NumberOfLines - 1 Then
ReDim Preserve out(j)
out(j) = arr(i)
j = j + 1
End If
Next i
Nb = FreeFile
Open StrFile For Output As #Nb
Print #Nb, Join(out, Chr(13))
Close #Nb
End If
End Sub

View file

@ -17,8 +17,8 @@ Sub remove_lines(filepath,start,number)
Do Until discard_count = number
InFile.SkipLine
discard_count = discard_count + 1
line_count = line_count + 1
Loop
line_count = line_count + 1
End If
Loop
InFile.Close