12-11-2003, 03:02 AM
I was writing a simple XOR encryption routine in VB 6 that encrypts a file, and I ran into a problem. Here's my code:
I get a runtime error: "Invalid Procedure Call or Argument" on the Put #2 line.
What wrong?
Code:
Dim inbyte As String
If infile.Text = "" Or outfile.Text = "" Then
MsgBox "You must specify both an Infile and an Outfile.", vbExclamation, "Error"
Exit Sub
End If
If code.Text = "" Then
MsgBox "You must specify a code.", vbExclamation, "Error"
Exit Sub
End If
If Val(code.Text) < 0 Or Val(code.Text) > 255 Then
MsgBox "Code specified must be between 0 and 255.", vbExclamation, "Error"
Exit Sub
End If
Open infile.Text For Binary As #1
Open outfile.Text For Binary As #2
For i = 1 To LOF(1)
Get #1, , inbyte
Put #2, , Chr(Asc(inbyte) Xor Val(code.Text))
Next
Close #1, #2
What wrong?