Reversefile

Reversing a file
This tip demonstrates how to reverse a whole file.
This function could be used as part of a security program to encode confidential data.

CodeFunctionName
What is this?

Public

Not Tested

Imported
Public Sub Reversefile(Sourcefile As String, Destfile As String)
' Sourcefile : file to get data from
' Destfile : file to put data in
' This does not work very well on strings as it does not seem to recognize new lines.
Dim mybyte() As Byte
Dim reversedbyte() As Byte
Dim reversebyte As Long
Close
Open Sourcefile For Binary As #1
Open Destfile For Binary As #2
ReDim mybyte(1 To LOF(1)) As Byte
ReDim reversedbyte(1 To LOF(1)) As Byte
Get #1, , mybyte
For reversebyte = UBound(mybyte) To 1 Step -1
reversedbyte(reversebyte) = mybyte(UBound(mybyte) - reversebyte + 1)
Next
Put #2, , reversedbyte
Close #2
Close #1
End Sub

SourceFile, Destfile

Views 4,682

Downloads 1,402

CodeID
DB ID

ANmarAmdeen
606
Revisions

v1.0

Saturday
June
16
2018