|
-
Sep 16th, 2000, 06:17 AM
#1
Thread Starter
Junior Member
When I write to a file using output access it always puts a return at the end of the text and makes it go to the next line. This is causing problems in my program. It's an encryption program that writes encrypted text to a file, and then can decrypt it. But because the return at the end is not encrypted, it decrypts to the wrong character.
This is the code I'm using to write it:
Open CurrentFile For Output As #1
Print #1, txtEncrypt.Text
Close #1
Anyone know how to make it not add the return at the end of the file?
Thanks
-
Sep 16th, 2000, 06:25 AM
#2
Hyperactive Member
VB does this by default. If you don't want a return at the end of the line, try writing to the file in Random mode.
-
Sep 16th, 2000, 07:16 AM
#3
_______
<?>
Code:
'example uses a textbox Text1
'2 command buttons, Command1, Command2
'
'encrypts and decrypts a file showing results in textbox
'
'use write instead of print when writing to the file
'this will remove the unwanted characters at end of file.
'
Option Explicit
'Encrypt/Unencrypt a file
'
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
Private Sub Command2_Click()
Text1 = ""
Dim intnum As Integer
intnum = FreeFile
Dim CurFile As String
CurFile = "C:\my documents\mytext.txt"
Call DecryptFile(CurFile, 4)
Open CurFile For Input As intnum
Text1 = StrConv(InputB(LOF(intnum), intnum), vbUnicode)
Close #1
End Sub
Private Sub Command1_Click()
Text1 = ""
Dim intnum As Integer
intnum = FreeFile
Dim CurFile As String
CurFile = "C:\my documents\mytext.txt"
Text1 = "Help me out here will you." & vbCrLf
Text1 = Text1 & "Ok, I'll try." & vbCrLf
Text1 = Text1 & "Hope this works."
Open CurFile For Output As intnum
Write #intnum, Text1
Close intnum
Call EncryptFile(CurFile, 4)
Text1 = ""
Open CurFile For Input As intnum
MsgBox LOF(intnum)
Text1 = StrConv(InputB(LOF(intnum), intnum), vbUnicode)
Close #1
End Sub
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
-
Sep 16th, 2000, 07:54 AM
#4
Thread Starter
Junior Member
HeSaidJoe, thanks but I've already done my own encryption and decryption code.
I just need to know how to stop VB from adding a return at the end of the file when i write it.
Thanks
-
Sep 16th, 2000, 07:56 AM
#5
Thread Starter
Junior Member
And also, using Write instead of Print still puts a return at the end.
-
Sep 16th, 2000, 07:57 AM
#6
_______
<?>
the example tells you that..take only what you need.
check the write functions as compared to yours.
I like to check before I post...that's why it's all there.
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
-
Sep 16th, 2000, 08:19 AM
#7
Thread Starter
Junior Member
ok thanks ive worked it out.
i just needed to change the code to this:
Open CurrentFile For Binary As #1
Put #1, 1, txtEncrypt.Text
Close #1
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|