AllAPI Network - The KPD-Team

 
Allapi Network
 API-Guide
 ApiViewer

 API List

 
API Resources
 Tips & Tricks
 VB Tutorials
 Error Lookup
 
Misc Stuff
 VB examples
 VB Tools
 VB Links
 Top Downloads
 
This Site
 Search Engine
 Contact Form
 

Donate to AllAPI.net

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")

 

 


Copyright © 1998-2007, The Mentalis.org Team - Privacy statement
Did you find a bug on this page? Tell us!
This site is located at http://allapi.mentalis.org/