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.
Function Code
Public Sub reversefile(fromfile _
As String, tofile As String)
' Fromfile: file to get data from
' Tofile: file to put data in
' Note: This does not work very
' well on strings as it does not seem to
' recognise new lines.
Dim mybyte() As Byte
Dim reversedbyte() As Byte
Dim reversebyte As Long
Open fromfile For Binary As #1
Open tofile 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
Use
call
reversefile("c:\fromfile.dat","c:\tofile.dat")
|