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.

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 655 Downloads 231

'Open', 'Binary'

ANmarAmdeen
326
Protection VBA
Revisions

v1.0