I want to save my high score list in a textfile. But I don't want anyone to be able to open it in wordpad and change it. How can I do take save it with "special" character.
Printable View
I want to save my high score list in a textfile. But I don't want anyone to be able to open it in wordpad and change it. How can I do take save it with "special" character.
Your could encrypt the file and unencrypt it when you want to open it.
[code]
'Encrypt/Unencrypt a file
'
Option Explicit
'
Private Function EncryptFile(sFile As String, iKey As Integer)
Dim iFake#
Dim x As String * 1
Dim lP As Long, z
Dim intNum#
intNum = FreeFile
iFake = Rnd(-1)
Randomize (iKey)
lP = 1
Open sFile For Binary As intNum
While lP <= LOF(intNum)
Get #intNum, lP, x
z = Asc(x) + Int(Rnd * 256)
If z > 255 Then z = z - 256
x = Chr(z)
Put #intNum, lP, x
lP = lP + 1
Wend
Close #intNum
MsgBox "Your file has been encrypted."
End Function
Private Function DecryptFile(sFile As String, iKey As Integer)
Dim iFake As Integer
Dim x As String * 1
Dim lP As Long, z
Dim intNum#
intNum = FreeFile
iFake = Rnd(-1)
Randomize (iKey)
lP = 1
Open sFile For Binary As #intNum
While lP <= LOF(intNum)
Get #intNum, lP, x
z = Asc(x) - Int(Rnd * 256)
If z < 0 Then z = z + 256
x = Chr(z)
Put #intNum, lP, x
lP = lP + 1
Wend
Close #intNum
MsgBox "Your file has been unencrypted."
End Function
' <<<< Form Event Code >>>>
Private Sub Command1_Click()
Call EncryptFile("a:\yourifle.doc", 44)
End Sub
Private Sub Command2_Click()
Call DecryptFile("a:\yourifle.doc", 44)
End Sub
[code]